
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Springmvc框架 · 书名</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="作者">
        <meta name="identifier" content="图书编号" scheme="ISBN">
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-intopic-toc/style.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-flexible-alerts/style.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="spring框架.html" />
    
    
    <link rel="prev" href="SpringBoot.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    书名
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">Books</li>
        
        
    
        <li class="chapter " data-level="2.1" >
            
                <span>
            
                    
                    Java
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1.1" data-path="../java/001环境变量.html">
            
                <a href="../java/001环境变量.html">
            
                    
                    001环境变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.2" data-path="../java/002Java初体验.html">
            
                <a href="../java/002Java初体验.html">
            
                    
                    002Java初体验
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.3" data-path="../java/003变量命名及数据类型.html">
            
                <a href="../java/003变量命名及数据类型.html">
            
                    
                    003变量命名及数据类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.4" data-path="../java/004运算符.html">
            
                <a href="../java/004运算符.html">
            
                    
                    004运算符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.5" data-path="../java/005选择结构.html">
            
                <a href="../java/005选择结构.html">
            
                    
                    005选择结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.6" data-path="../java/006循环结构.html">
            
                <a href="../java/006循环结构.html">
            
                    
                    006循环结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.7" data-path="../java/007数组.html">
            
                <a href="../java/007数组.html">
            
                    
                    007数组
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.8" data-path="../java/008类和对象方法.html">
            
                <a href="../java/008类和对象方法.html">
            
                    
                    008类和对象方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.9" data-path="../java/009构造方法.html">
            
                <a href="../java/009构造方法.html">
            
                    
                    009构造方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.10" data-path="../java/010封装与关键字static.html">
            
                <a href="../java/010封装与关键字static.html">
            
                    
                    010封装与关键字Static
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.11" data-path="../java/011 继承.html">
            
                <a href="../java/011 继承.html">
            
                    
                    011 继承
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.12" data-path="../java/012方法重写.html">
            
                <a href="../java/012方法重写.html">
            
                    
                    012方法重写
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.13" data-path="../java/013多态.html">
            
                <a href="../java/013多态.html">
            
                    
                    013多态
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.14" data-path="../java/014抽象类抽象方法.html">
            
                <a href="../java/014抽象类抽象方法.html">
            
                    
                    014抽象类抽象方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.15" data-path="../java/015接口.html">
            
                <a href="../java/015接口.html">
            
                    
                    015接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.16" data-path="../java/016异常.html">
            
                <a href="../java/016异常.html">
            
                    
                    016异常
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.17" data-path="../java/017集合.html">
            
                <a href="../java/017集合.html">
            
                    
                    017集合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.18" data-path="../java/017集合2.html">
            
                <a href="../java/017集合2.html">
            
                    
                    017集合2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.19" data-path="../java/018泛型.html">
            
                <a href="../java/018泛型.html">
            
                    
                    018泛型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.20" data-path="../java/019Collections算法类.html">
            
                <a href="../java/019Collections算法类.html">
            
                    
                    019Collections算法类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.21" data-path="../java/020枚举.html">
            
                <a href="../java/020枚举.html">
            
                    
                    020枚举
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.22" data-path="../java/021包装类.html">
            
                <a href="../java/021包装类.html">
            
                    
                    021包装类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.23" data-path="../java/022常用类.html">
            
                <a href="../java/022常用类.html">
            
                    
                    022常用类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.24" data-path="../java/023File类.html">
            
                <a href="../java/023File类.html">
            
                    
                    023File类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.25" data-path="../java/024IO流.html">
            
                <a href="../java/024IO流.html">
            
                    
                    024IO流
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.26" data-path="../java/025多线程.html">
            
                <a href="../java/025多线程.html">
            
                    
                    025多线程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.27" data-path="../java/025多线程线程池.html">
            
                <a href="../java/025多线程线程池.html">
            
                    
                    025多线程线程池
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.28" data-path="../java/026网络编程Socket.html">
            
                <a href="../java/026网络编程Socket.html">
            
                    
                    026网络编程Socket
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.29" data-path="../java/027XML解析.html">
            
                <a href="../java/027XML解析.html">
            
                    
                    027XML解析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.30" data-path="../java/028 注解.html">
            
                <a href="../java/028 注解.html">
            
                    
                    028 注解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.31" data-path="../java/029 Lambda表达式.html">
            
                <a href="../java/029 Lambda表达式.html">
            
                    
                    029 Lambda表达式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.32" data-path="../java/029 反射.html">
            
                <a href="../java/029 反射.html">
            
                    
                    029 反射
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.2" >
            
                <span>
            
                    
                    Mybatis
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.2.1" data-path="../mybatis/MyBatis.html">
            
                <a href="../mybatis/MyBatis.html">
            
                    
                    MyBatis
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.2.1.1" >
            
                <span>
            
                    
                    MyBatis
            
                </span>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.3" >
            
                <span>
            
                    
                    Mysql
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.3.1" data-path="../mysql/01 SQL通用语法.html">
            
                <a href="../mysql/01 SQL通用语法.html">
            
                    
                    01 SQL通用语法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.2" data-path="../mysql/02 DDL.html">
            
                <a href="../mysql/02 DDL.html">
            
                    
                    02 DDL
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.3" data-path="../mysql/03 DML.html">
            
                <a href="../mysql/03 DML.html">
            
                    
                    03 DML
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.4" data-path="../mysql/04 DQL.html">
            
                <a href="../mysql/04 DQL.html">
            
                    
                    04 DQL
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.5" data-path="../mysql/05 DCL.html">
            
                <a href="../mysql/05 DCL.html">
            
                    
                    05 DCL
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.6" data-path="../mysql/06 函数.html">
            
                <a href="../mysql/06 函数.html">
            
                    
                    06 函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.7" data-path="../mysql/07 约束.html">
            
                <a href="../mysql/07 约束.html">
            
                    
                    07 约束
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.8" data-path="../mysql/08 多表查询.html">
            
                <a href="../mysql/08 多表查询.html">
            
                    
                    08 多表查询
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.9" data-path="../mysql/09 事务.html">
            
                <a href="../mysql/09 事务.html">
            
                    
                    09 事务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.10" data-path="../mysql/999zzz.html">
            
                <a href="../mysql/999zzz.html">
            
                    
                    999zzz
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.11" data-path="../mysql/MySql.html">
            
                <a href="../mysql/MySql.html">
            
                    
                    MySql
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.12" data-path="../mysql/sql.html">
            
                <a href="../mysql/sql.html">
            
                    
                    Sql
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.4" >
            
                <span>
            
                    
                    Spring
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.4.1" data-path="../spring/spring.html">
            
                <a href="../spring/spring.html">
            
                    
                    Spring
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.5" >
            
                <span>
            
                    
                    SpringMVC
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.5.1" data-path="../springMVC/springMVC.html">
            
                <a href="../springMVC/springMVC.html">
            
                    
                    SpringMVC
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.6" >
            
                <span>
            
                    
                    整合
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.6.1" data-path="Mybatis框架.html">
            
                <a href="Mybatis框架.html">
            
                    
                    Mybatis框架
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.2" data-path="SpringBoot.html">
            
                <a href="SpringBoot.html">
            
                    
                    SpringBoot
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="2.6.3" data-path="springmvc框架.html">
            
                <a href="springmvc框架.html">
            
                    
                    Springmvc框架
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.4" data-path="spring框架.html">
            
                <a href="spring框架.html">
            
                    
                    Spring框架
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >Springmvc框架</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="springmvc&#x6846;&#x67B6;">SpringMVC&#x6846;&#x67B6;</h1>
<h2 id="mvc&#x6982;&#x8FF0;">MVC&#x6982;&#x8FF0;</h2>
<p>MVC &#x8BBE;&#x8BA1;&#x6A21;&#x5F0F;&#x4E00;&#x822C;&#x6307; MVC &#x6846;&#x67B6;&#xFF0C;M&#xFF08;Model&#xFF09;&#x6307;&#x6570;&#x636E;&#x6A21;&#x578B;&#x5C42;&#xFF0C;&#x4E1A;&#x52A1;&#x6A21;&#x578B;&#x5C42;&#xFF0C;V&#xFF08;View&#xFF09;&#x6307;&#x89C6;&#x56FE;&#x5C42;&#xFF0C;C&#xFF08;Controller&#xFF09;&#x6307;&#x63A7;&#x5236;&#x5C42;&#x3002;&#x4F7F;&#x7528; MVC &#x7684;&#x76EE;&#x7684;&#x662F;&#x5C06; M &#x548C; V &#x7684;&#x5B9E;&#x73B0;&#x4EE3;&#x7801;&#x5206;&#x79BB;&#xFF0C;&#x4F7F;&#x540C;&#x4E00;&#x4E2A;&#x7A0B;&#x5E8F;&#x53EF;&#x4EE5;&#x6709;&#x4E0D;&#x540C;&#x7684;&#x8868;&#x73B0;&#x5F62;&#x5F0F;&#x3002;&#x5176;&#x4E2D;&#xFF0C;View &#x7684;&#x5B9A;&#x4E49;&#x6BD4;&#x8F83;&#x6E05;&#x6670;&#xFF0C;&#x5C31;&#x662F;&#x7528;&#x6237;&#x754C;&#x9762;.</p>
<p>&#x5728;&#x5B66;&#x4E60; Servlet &#x53CA; JSP &#x5F00;&#x53D1;&#x65F6;&#xFF0C;JavaBean &#x76F8;&#x5F53;&#x4E8E; Model&#xFF0C;Servlet &#x76F8;&#x5F53;&#x4E8E; Controller&#xFF0C;JSP &#x76F8;&#x5F53;&#x4E8E; View&#x3002;</p>
<p>&#x603B;&#x7ED3;&#x5982;&#x4E0B;&#xFF1A;</p>
<ul>
<li>&#x89C6;&#x56FE;&#x5C42;&#xFF08;View&#xFF09;&#xFF1A;&#x8D1F;&#x8D23;&#x683C;&#x5F0F;&#x5316;&#x6570;&#x636E;&#x5E76;&#x628A;&#x5B83;&#x4EEC;&#x5448;&#x73B0;&#x7ED9;&#x7528;&#x6237;&#xFF0C;&#x5305;&#x62EC;&#x6570;&#x636E;&#x5C55;&#x793A;&#x3001;&#x7528;&#x6237;&#x4EA4;&#x4E92;&#x3001;&#x6570;&#x636E;&#x9A8C;&#x8BC1;&#x3001;&#x754C;&#x9762;&#x8BBE;&#x8BA1;&#x7B49;&#x529F;&#x80FD;&#x3002;</li>
<li>&#x63A7;&#x5236;&#x5C42;&#xFF08;Controller&#xFF09;&#xFF1A;&#x8D1F;&#x8D23;&#x63A5;&#x6536;&#x5E76;&#x8F6C;&#x53D1;&#x8BF7;&#x6C42;&#xFF0C;&#x5BF9;&#x8BF7;&#x6C42;&#x8FDB;&#x884C;&#x5904;&#x7406;&#x540E;&#xFF0C;&#x6307;&#x5B9A;&#x89C6;&#x56FE;&#x5E76;&#x5C06;&#x54CD;&#x5E94;&#x7ED3;&#x679C;&#x53D1;&#x9001;&#x7ED9;&#x5BA2;&#x6237;&#x7AEF;&#x3002;</li>
<li>&#x6570;&#x636E;&#x6A21;&#x578B;&#x5C42;&#xFF08;Model&#xFF09;&#xFF1A;&#x6A21;&#x578B;&#x5BF9;&#x8C61;&#x62E5;&#x6709;&#x6700;&#x591A;&#x7684;&#x5904;&#x7406;&#x4EFB;&#x52A1;&#xFF0C;&#x662F;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x7684;&#x4E3B;&#x4F53;&#x90E8;&#x5206;&#xFF0C;&#x5B83;&#x8D1F;&#x8D23;&#x6570;&#x636E;&#x903B;&#x8F91;&#xFF08;&#x4E1A;&#x52A1;&#x89C4;&#x5219;&#xFF09;&#x7684;&#x5904;&#x7406;&#x548C;&#x5B9E;&#x73B0;&#x6570;&#x636E;&#x64CD;&#x4F5C;&#xFF08;&#x5373;&#x5728;&#x6570;&#x636E;&#x5E93;&#x4E2D;&#x5B58;&#x53D6;&#x6570;&#x636E;&#xFF09;</li>
</ul>
<p><strong>MVC&#x4F18;&#x7F3A;&#x70B9;</strong></p>
<p>&#x4EFB;&#x4F55;&#x4E00;&#x4EF6;&#x4E8B;&#x90FD;&#x6709;&#x5229;&#x6709;&#x5F0A;&#xFF0C;&#x4E0B;&#x9762;&#x6765;&#x4E86;&#x89E3;&#x4E00;&#x4E0B; MVC &#x7684;&#x4F18;&#x7F3A;&#x70B9;&#x3002;</p>
<p><strong>&#x4F18;&#x70B9;</strong></p>
<ul>
<li>&#x591A;&#x89C6;&#x56FE;&#x5171;&#x4EAB;&#x4E00;&#x4E2A;&#x6A21;&#x578B;&#xFF0C;&#x5927;&#x5927;&#x63D0;&#x9AD8;&#x4E86;&#x4EE3;&#x7801;&#x7684;&#x53EF;&#x91CD;&#x7528;&#x6027;</li>
<li>MVC &#x4E09;&#x4E2A;&#x6A21;&#x5757;&#x76F8;&#x4E92;&#x72EC;&#x7ACB;&#xFF0C;&#x677E;&#x8026;&#x5408;&#x67B6;&#x6784;</li>
<li>&#x63A7;&#x5236;&#x5668;&#x63D0;&#x9AD8;&#x4E86;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x7684;&#x7075;&#x6D3B;&#x6027;&#x548C;&#x53EF;&#x914D;&#x7F6E;&#x6027;</li>
<li>&#x6709;&#x5229;&#x4E8E;&#x8F6F;&#x4EF6;&#x5DE5;&#x7A0B;&#x5316;&#x7BA1;&#x7406;</li>
</ul>
<p>&#x603B;&#x4E4B;&#xFF0C;&#x6211;&#x4EEC;&#x901A;&#x8FC7; MVC &#x8BBE;&#x8BA1;&#x6A21;&#x5F0F;&#x6700;&#x7EC8;&#x53EF;&#x4EE5;&#x6253;&#x9020;&#x51FA;&#x4E00;&#x4E2A;&#x677E;&#x8026;&#x5408;+&#x9AD8;&#x53EF;&#x91CD;&#x7528;&#x6027;+&#x9AD8;&#x53EF;&#x9002;&#x7528;&#x6027;&#x7684;&#x5B8C;&#x7F8E;&#x67B6;&#x6784;&#x3002;</p>
<p><strong>&#x7F3A;&#x70B9;</strong></p>
<ul>
<li>&#x539F;&#x7406;&#x590D;&#x6742;</li>
<li>&#x589E;&#x52A0;&#x4E86;&#x7CFB;&#x7EDF;&#x7ED3;&#x6784;&#x548C;&#x5B9E;&#x73B0;&#x7684;&#x590D;&#x6742;&#x6027;</li>
<li>&#x89C6;&#x56FE;&#x5BF9;&#x6A21;&#x578B;&#x6570;&#x636E;&#x7684;&#x4F4E;&#x6548;&#x7387;&#x8BBF;&#x95EE;</li>
</ul>
<h2 id="springmvc&#x6982;&#x8FF0;">SpringMVC&#x6982;&#x8FF0;</h2>
<p>Spring MVC &#x662F; Spring &#x63D0;&#x4F9B;&#x7684;&#x4E00;&#x4E2A;&#x57FA;&#x4E8E; MVC &#x8BBE;&#x8BA1;&#x6A21;&#x5F0F;&#x7684;&#x8F7B;&#x91CF;&#x7EA7; Web &#x5F00;&#x53D1;&#x6846;&#x67B6;&#xFF0C;&#x672C;&#x8D28;&#x4E0A;&#x76F8;&#x5F53;&#x4E8E; Servlet&#x3002;</p>
<p>Spring MVC &#x662F;&#x7ED3;&#x6784;&#x6700;&#x6E05;&#x6670;&#x7684; Servlet+JSP+JavaBean &#x7684;&#x5B9E;&#x73B0;&#xFF0C;&#x662F;&#x4E00;&#x4E2A;&#x5178;&#x578B;&#x7684;&#x6559;&#x79D1;&#x4E66;&#x5F0F;&#x7684; MVC &#x6784;&#x67B6;&#xFF0C;&#x4E0D;&#x50CF; Struts &#x7B49;&#x5176;&#x5B83;&#x6846;&#x67B6;&#x90FD;&#x662F;&#x53D8;&#x79CD;&#x6216;&#x8005;&#x4E0D;&#x662F;&#x5B8C;&#x5168;&#x57FA;&#x4E8E; MVC &#x7CFB;&#x7EDF;&#x7684;&#x6846;&#x67B6;&#x3002;</p>
<p>Spring MVC &#x89D2;&#x8272;&#x5212;&#x5206;&#x6E05;&#x6670;&#xFF0C;&#x5206;&#x5DE5;&#x660E;&#x7EC6;&#xFF0C;&#x5E76;&#x4E14;&#x548C; Spring &#x6846;&#x67B6;&#x65E0;&#x7F1D;&#x7ED3;&#x5408;&#x3002;Spring MVC &#x662F;&#x5F53;&#x4ECA;&#x4E1A;&#x754C;&#x6700;&#x4E3B;&#x6D41;&#x7684; Web &#x5F00;&#x53D1;&#x6846;&#x67B6;&#xFF0C;&#x4EE5;&#x53CA;&#x6700;&#x70ED;&#x95E8;&#x7684;&#x5F00;&#x53D1;&#x6280;&#x80FD;&#x3002;</p>
<p>&#x5728; Spring MVC &#x6846;&#x67B6;&#x4E2D;&#xFF0C;Controller &#x66FF;&#x6362; Servlet &#x6765;&#x62C5;&#x8D1F;&#x63A7;&#x5236;&#x5668;&#x7684;&#x804C;&#x8D23;&#xFF0C;&#x7528;&#x4E8E;&#x63A5;&#x6536;&#x8BF7;&#x6C42;&#xFF0C;&#x8C03;&#x7528;&#x76F8;&#x5E94;&#x7684; Model &#x8FDB;&#x884C;&#x5904;&#x7406;&#xFF0C;&#x5904;&#x7406;&#x5668;&#x5B8C;&#x6210;&#x4E1A;&#x52A1;&#x5904;&#x7406;&#x540E;&#x8FD4;&#x56DE;&#x5904;&#x7406;&#x7ED3;&#x679C;&#x3002;Controller &#x8C03;&#x7528;&#x76F8;&#x5E94;&#x7684; View &#x5E76;&#x5BF9;&#x5904;&#x7406;&#x7ED3;&#x679C;&#x8FDB;&#x884C;&#x89C6;&#x56FE;&#x6E32;&#x67D3;&#xFF0C;&#x6700;&#x7EC8;&#x5BA2;&#x6237;&#x7AEF;&#x5F97;&#x5230;&#x54CD;&#x5E94;&#x4FE1;&#x606F;&#x3002;</p>
<p>Spring MVC &#x6846;&#x67B6;&#x91C7;&#x7528;&#x677E;&#x8026;&#x5408;&#x53EF;&#x63D2;&#x62D4;&#x7684;&#x7EC4;&#x4EF6;&#x7ED3;&#x6784;&#xFF0C;&#x5177;&#x6709;&#x9AD8;&#x5EA6;&#x53EF;&#x914D;&#x7F6E;&#x6027;&#xFF0C;&#x6BD4;&#x8D77;&#x5176;&#x5B83; MVC &#x6846;&#x67B6;&#x66F4;&#x5177;&#x6709;&#x6269;&#x5C55;&#x6027;&#x548C;&#x7075;&#x6D3B;&#x6027;&#x3002;</p>
<p><strong>Spring MVC&#x4F18;&#x70B9;</strong></p>
<ul>
<li>&#x6E05;&#x6670;&#x5730;&#x89D2;&#x8272;&#x5212;&#x5206;&#xFF0C;Spring MVC &#x5728; Model&#x3001;View &#x548C; Controller &#x65B9;&#x9762;&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x4E2A;&#x975E;&#x5E38;&#x6E05;&#x6670;&#x7684;&#x89D2;&#x8272;&#x5212;&#x5206;&#xFF0C;&#x8FD9; 3 &#x4E2A;&#x65B9;&#x9762;&#x771F;&#x6B63;&#x662F;&#x5404;&#x53F8;&#x5176;&#x804C;&#xFF0C;&#x5404;&#x8D1F;&#x5176;&#x8D23;&#x3002;</li>
<li>&#x7075;&#x6D3B;&#x7684;&#x914D;&#x7F6E;&#x529F;&#x80FD;&#xFF0C;&#x53EF;&#x4EE5;&#x628A;&#x7C7B;&#x5F53;&#x4F5C; Bean &#x901A;&#x8FC7; XML &#x8FDB;&#x884C;&#x914D;&#x7F6E;&#x3002;</li>
<li>&#x63D0;&#x4F9B;&#x4E86;&#x5927;&#x91CF;&#x7684;&#x63A7;&#x5236;&#x5668;&#x63A5;&#x53E3;&#x548C;&#x5B9E;&#x73B0;&#x7C7B;&#xFF0C;&#x5F00;&#x53D1;&#x8005;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; Spring &#x63D0;&#x4F9B;&#x7684;&#x63A7;&#x5236;&#x5668;&#x5B9E;&#x73B0;&#x7C7B;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x81EA;&#x5DF1;&#x5B9E;&#x73B0;&#x63A7;&#x5236;&#x5668;&#x63A5;&#x53E3;&#x3002;</li>
<li>&#x771F;&#x6B63;&#x505A;&#x5230;&#x4E0E; View &#x5C42;&#x7684;&#x5B9E;&#x73B0;&#x65E0;&#x5173;&#x3002;&#x5B83;&#x4E0D;&#x4F1A;&#x5F3A;&#x5236;&#x5F00;&#x53D1;&#x8005;&#x4F7F;&#x7528; JSP&#xFF0C;&#x53EF;&#x4EE5;&#x6839;&#x636E;&#x9879;&#x76EE;&#x9700;&#x6C42;&#x4F7F;&#x7528; Velocity&#x3001;FreeMarker &#x7B49;&#x6280;&#x672F;&#x3002;</li>
<li>&#x56FD;&#x9645;&#x5316;&#x652F;&#x6301;</li>
<li>&#x9762;&#x5411;&#x63A5;&#x53E3;&#x7F16;&#x7A0B;</li>
<li>&#x4E0E; Spring &#x6846;&#x67B6;&#x65E0;&#x7F1D;&#x96C6;&#x6210;</li>
</ul>
<h2 id="springmvc&#x6267;&#x884C;&#x6D41;&#x7A0B;">SpringMVC&#x6267;&#x884C;&#x6D41;&#x7A0B;</h2>
<p>Spring MVC &#x6846;&#x67B6;&#x662F;&#x9AD8;&#x5EA6;&#x53EF;&#x914D;&#x7F6E;&#x7684;&#xFF0C;&#x5305;&#x542B;&#x591A;&#x79CD;&#x89C6;&#x56FE;&#x6280;&#x672F;&#xFF0C;&#x4F8B;&#x5982; JSP&#x3001;FreeMarke&#x548C; POI&#x3002;Spring MVC &#x6846;&#x67B6;&#x5E76;&#x4E0D;&#x5173;&#x5FC3;&#x4F7F;&#x7528;&#x7684;&#x89C6;&#x56FE;&#x6280;&#x672F;&#xFF0C;&#x4E5F;&#x4E0D;&#x4F1A;&#x5F3A;&#x8FEB;&#x5F00;&#x53D1;&#x8005;&#x53EA;&#x4F7F;&#x7528; JSP&#x3002;</p>
<p><strong>Spring MVC &#x6267;&#x884C;&#x6D41;&#x7A0B;&#x5982;&#x56FE; &#x6240;&#x793A;&#xFF1A;</strong></p>
<p><img src="springmvc&#x6846;&#x67B6;.assets/&#x6D41;&#x7A0B;.png" alt="&#x6D41;&#x7A0B;"></p>
<p><strong>SpringMVC &#x7684;&#x6267;&#x884C;&#x6D41;&#x7A0B;&#x5982;&#x4E0B;:</strong></p>
<ol>
<li>&#x7528;&#x6237;&#x70B9;&#x51FB;&#x67D0;&#x4E2A;&#x8BF7;&#x6C42;&#x8DEF;&#x5F84;&#xFF0C;&#x53D1;&#x8D77;&#x4E00;&#x4E2A; HTTP request &#x8BF7;&#x6C42;&#xFF0C;&#x8BE5;&#x8BF7;&#x6C42;&#x4F1A;&#x88AB;&#x63D0;&#x4EA4;&#x5230; DispatcherServlet&#xFF08;&#x524D;&#x7AEF;&#x63A7;&#x5236;&#x5668;&#xFF09;&#xFF1B;</li>
<li>&#x7531; DispatcherServlet &#x8BF7;&#x6C42;&#x4E00;&#x4E2A;&#x6216;&#x591A;&#x4E2A; HandlerMapping&#xFF08;&#x5904;&#x7406;&#x5668;&#x6620;&#x5C04;&#x5668;&#xFF09;&#xFF0C;&#x5E76;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x6267;&#x884C;&#x94FE;&#xFF08;HandlerExecutionChain&#xFF09;&#x3002;</li>
<li>DispatcherServlet &#x5C06;&#x6267;&#x884C;&#x94FE;&#x8FD4;&#x56DE;&#x7684; Handler &#x4FE1;&#x606F;&#x53D1;&#x9001;&#x7ED9; HandlerAdapter&#xFF08;&#x5904;&#x7406;&#x5668;&#x9002;&#x914D;&#x5668;&#xFF09;&#xFF1B;</li>
<li>HandlerAdapter &#x6839;&#x636E; Handler &#x4FE1;&#x606F;&#x627E;&#x5230;&#x5E76;&#x6267;&#x884C;&#x76F8;&#x5E94;&#x7684; Handler&#xFF08;&#x5E38;&#x79F0;&#x4E3A; Controller&#xFF09;&#xFF1B;</li>
<li>Handler &#x6267;&#x884C;&#x5B8C;&#x6BD5;&#x540E;&#x4F1A;&#x8FD4;&#x56DE;&#x7ED9; HandlerAdapter &#x4E00;&#x4E2A; ModelAndView &#x5BF9;&#x8C61;&#xFF08;Spring MVC&#x7684;&#x5E95;&#x5C42;&#x5BF9;&#x8C61;&#xFF0C;&#x5305;&#x62EC; Model &#x6570;&#x636E;&#x6A21;&#x578B;&#x548C; View &#x89C6;&#x56FE;&#x4FE1;&#x606F;&#xFF09;&#xFF1B;</li>
<li>HandlerAdapter &#x63A5;&#x6536;&#x5230; ModelAndView &#x5BF9;&#x8C61;&#x540E;&#xFF0C;&#x5C06;&#x5176;&#x8FD4;&#x56DE;&#x7ED9; DispatcherServlet &#xFF1B;</li>
<li>DispatcherServlet &#x63A5;&#x6536;&#x5230; ModelAndView &#x5BF9;&#x8C61;&#x540E;&#xFF0C;&#x4F1A;&#x8BF7;&#x6C42; ViewResolver&#xFF08;&#x89C6;&#x56FE;&#x89E3;&#x6790;&#x5668;&#xFF09;&#x5BF9;&#x89C6;&#x56FE;&#x8FDB;&#x884C;&#x89E3;&#x6790;&#xFF1B;</li>
<li>ViewResolver &#x6839;&#x636E; View &#x4FE1;&#x606F;&#x5339;&#x914D;&#x5230;&#x76F8;&#x5E94;&#x7684;&#x89C6;&#x56FE;&#x7ED3;&#x679C;&#xFF0C;&#x5E76;&#x8FD4;&#x56DE;&#x7ED9; DispatcherServlet&#xFF1B;</li>
<li>DispatcherServlet &#x63A5;&#x6536;&#x5230;&#x5177;&#x4F53;&#x7684; View &#x89C6;&#x56FE;&#x540E;&#xFF0C;&#x8FDB;&#x884C;&#x89C6;&#x56FE;&#x6E32;&#x67D3;&#xFF0C;&#x5C06; Model &#x4E2D;&#x7684;&#x6A21;&#x578B;&#x6570;&#x636E;&#x586B;&#x5145;&#x5230; View &#x89C6;&#x56FE;&#x4E2D;&#x7684; request &#x57DF;&#xFF0C;&#x751F;&#x6210;&#x6700;&#x7EC8;&#x7684; View&#xFF08;&#x89C6;&#x56FE;&#xFF09;&#xFF1B;</li>
<li>&#x89C6;&#x56FE;&#x8D1F;&#x8D23;&#x5C06;&#x7ED3;&#x679C;&#x663E;&#x793A;&#x5230;&#x6D4F;&#x89C8;&#x5668;&#xFF08;&#x5BA2;&#x6237;&#x7AEF;&#xFF09;</li>
</ol>
<h2 id="springmvc&#x6838;&#x5FC3;&#x7EC4;&#x4EF6;&#x4ECB;&#x7ECD;">SpringMVC&#x6838;&#x5FC3;&#x7EC4;&#x4EF6;&#x4ECB;&#x7ECD;</h2>
<p>Spring MVC &#x6D89;&#x53CA;&#x5230;&#x7684;&#x7EC4;&#x4EF6;&#x6709; DispatcherServlet&#xFF08;&#x524D;&#x7AEF;&#x63A7;&#x5236;&#x5668;&#xFF09;&#x3001;HandlerMapping&#xFF08;&#x5904;&#x7406;&#x5668;&#x6620;&#x5C04;&#x5668;&#xFF09;&#x3001;HandlerAdapter&#xFF08;&#x5904;&#x7406;&#x5668;&#x9002;&#x914D;&#x5668;&#xFF09;&#x3001;Handler&#xFF08;&#x5904;&#x7406;&#x5668;&#xFF09;&#x3001;ViewResolver&#xFF08;&#x89C6;&#x56FE;&#x89E3;&#x6790;&#x5668;&#xFF09;&#x548C; View&#xFF08;&#x89C6;&#x56FE;&#xFF09;&#x3002;&#x4E0B;&#x9762;&#x5BF9;&#x5404;&#x4E2A;&#x7EC4;&#x4EF6;&#x7684;&#x529F;&#x80FD;&#x8BF4;&#x660E;&#x5982;&#x4E0B;&#x3002;</p>
<p>1&#xFF09;DispatcherServlet</p>
<p>DispatcherServlet &#x662F;&#x524D;&#x7AEF;&#x63A7;&#x5236;&#x5668;&#xFF0C;&#x4ECE;&#x56FE; 1 &#x53EF;&#x4EE5;&#x770B;&#x51FA;&#xFF0C;Spring MVC &#x7684;&#x6240;&#x6709;&#x8BF7;&#x6C42;&#x90FD;&#x8981;&#x7ECF;&#x8FC7; DispatcherServlet &#x6765;&#x7EDF;&#x4E00;&#x5206;&#x53D1;&#x3002;DispatcherServlet &#x76F8;&#x5F53;&#x4E8E;&#x4E00;&#x4E2A;&#x8F6C;&#x53D1;&#x5668;&#x6216;&#x4E2D;&#x592E;&#x5904;&#x7406;&#x5668;&#xFF0C;&#x63A7;&#x5236;&#x6574;&#x4E2A;&#x6D41;&#x7A0B;&#x7684;&#x6267;&#x884C;&#xFF0C;&#x5BF9;&#x5404;&#x4E2A;&#x7EC4;&#x4EF6;&#x8FDB;&#x884C;&#x7EDF;&#x4E00;&#x8C03;&#x5EA6;&#xFF0C;&#x4EE5;&#x964D;&#x4F4E;&#x7EC4;&#x4EF6;&#x4E4B;&#x95F4;&#x7684;&#x8026;&#x5408;&#x6027;&#xFF0C;&#x6709;&#x5229;&#x4E8E;&#x7EC4;&#x4EF6;&#x4E4B;&#x95F4;&#x7684;&#x62D3;&#x5C55;&#x3002;</p>
<p>2&#xFF09;HandlerMapping</p>
<p>HandlerMapping &#x662F;&#x5904;&#x7406;&#x5668;&#x6620;&#x5C04;&#x5668;&#xFF0C;&#x5176;&#x4F5C;&#x7528;&#x662F;&#x6839;&#x636E;&#x8BF7;&#x6C42;&#x7684; URL &#x8DEF;&#x5F84;&#xFF0C;&#x901A;&#x8FC7;&#x6CE8;&#x89E3;&#x6216;&#x8005; XML &#x914D;&#x7F6E;&#xFF0C;&#x5BFB;&#x627E;&#x5339;&#x914D;&#x7684;&#x5904;&#x7406;&#x5668;&#xFF08;Handler&#xFF09;&#x4FE1;&#x606F;&#x3002;</p>
<p>3&#xFF09;HandlerAdapter</p>
<p>HandlerAdapter &#x662F;&#x5904;&#x7406;&#x5668;&#x9002;&#x914D;&#x5668;&#xFF0C;&#x5176;&#x4F5C;&#x7528;&#x662F;&#x6839;&#x636E;&#x6620;&#x5C04;&#x5668;&#x627E;&#x5230;&#x7684;&#x5904;&#x7406;&#x5668;&#xFF08;Handler&#xFF09;&#x4FE1;&#x606F;&#xFF0C;&#x6309;&#x7167;&#x7279;&#x5B9A;&#x89C4;&#x5219;&#x6267;&#x884C;&#x76F8;&#x5173;&#x7684;&#x5904;&#x7406;&#x5668;&#xFF08;Handler&#xFF09;&#x3002;</p>
<p>4&#xFF09;Handler</p>
<p>Handler &#x662F;&#x5904;&#x7406;&#x5668;&#xFF0C;&#x548C; Java Servlet &#x626E;&#x6F14;&#x7684;&#x89D2;&#x8272;&#x4E00;&#x81F4;&#x3002;&#x5176;&#x4F5C;&#x7528;&#x662F;&#x6267;&#x884C;&#x76F8;&#x5173;&#x7684;&#x8BF7;&#x6C42;&#x5904;&#x7406;&#x903B;&#x8F91;&#xFF0C;&#x5E76;&#x8FD4;&#x56DE;&#x76F8;&#x5E94;&#x7684;&#x6570;&#x636E;&#x548C;&#x89C6;&#x56FE;&#x4FE1;&#x606F;&#xFF0C;&#x5C06;&#x5176;&#x5C01;&#x88C5;&#x81F3; ModelAndView &#x5BF9;&#x8C61;&#x4E2D;&#x3002;</p>
<p>5&#xFF09;View Resolver</p>
<p>View Resolver &#x662F;&#x89C6;&#x56FE;&#x89E3;&#x6790;&#x5668;&#xFF0C;&#x5176;&#x4F5C;&#x7528;&#x662F;&#x8FDB;&#x884C;&#x89E3;&#x6790;&#x64CD;&#x4F5C;&#xFF0C;&#x901A;&#x8FC7; ModelAndView &#x5BF9;&#x8C61;&#x4E2D;&#x7684; View &#x4FE1;&#x606F;&#x5C06;&#x903B;&#x8F91;&#x89C6;&#x56FE;&#x540D;&#x89E3;&#x6790;&#x6210;&#x771F;&#x6B63;&#x7684;&#x89C6;&#x56FE; View&#xFF08;&#x5982;&#x901A;&#x8FC7;&#x4E00;&#x4E2A; JSP &#x8DEF;&#x5F84;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x771F;&#x6B63;&#x7684; JSP &#x9875;&#x9762;&#xFF09;</p>
<p>6&#xFF09;View</p>
<p>View &#x662F;&#x89C6;&#x56FE;&#xFF0C;&#x5176;&#x672C;&#x8EAB;&#x662F;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;&#xFF0C;&#x5B9E;&#x73B0;&#x7C7B;&#x652F;&#x6301;&#x4E0D;&#x540C;&#x7684; View &#x7C7B;&#x578B;&#xFF08;JSP&#x3001;FreeMarker&#x3001;Excel &#x7B49;&#xFF09;&#x3002;</p>
<p>&#x4EE5;&#x4E0A;&#x7EC4;&#x4EF6;&#x4E2D;&#xFF0C;&#x9700;&#x8981;&#x5F00;&#x53D1;&#x4EBA;&#x5458;&#x8FDB;&#x884C;&#x5F00;&#x53D1;&#x7684;&#x662F;&#x5904;&#x7406;&#x5668;&#xFF08;Handler&#xFF0C;&#x5E38;&#x79F0;Controller&#xFF09;&#x548C;&#x89C6;&#x56FE;&#xFF08;View&#xFF09;&#x3002;&#x901A;&#x4FD7;&#x7684;&#x8BF4;&#xFF0C;&#x8981;&#x5F00;&#x53D1;&#x5904;&#x7406;&#x8BE5;&#x8BF7;&#x6C42;&#x7684;&#x5177;&#x4F53;&#x4EE3;&#x7801;&#x903B;&#x8F91;&#xFF0C;&#x4EE5;&#x53CA;&#x6700;&#x7EC8;&#x5C55;&#x793A;&#x7ED9;&#x7528;&#x6237;&#x7684;&#x754C;&#x9762;</p>
<h2 id="&#x5FEB;&#x901F;&#x6784;&#x5EFA;spring-mvc&#x7A0B;&#x5E8F;">&#x5FEB;&#x901F;&#x6784;&#x5EFA;Spring MVC&#x7A0B;&#x5E8F;</h2>
<p><strong>&#x642D;&#x5EFA;&#x6B65;&#x9AA4;&#x5982;&#x4E0B;&#xFF1A;</strong></p>
<ol>
<li><p>&#x521B;&#x5EFA; Web &#x5E94;&#x7528;&#x5E76;&#x5F15;&#x5165; JAR &#x5305;</p>
<p>spring-webmvc</p>
</li>
<li><p>Spring MVC &#x914D;&#x7F6E;&#xFF1A;&#x5728; web.xml &#x4E2D;&#x914D;&#x7F6E; Servlet&#xFF0C;&#x521B;&#x5EFA; Spring MVC &#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;</p>
</li>
</ol>
<pre><code class="lang-xml"> <span class="hljs-tag">&lt;<span class="hljs-name">servlet</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">servlet-name</span>&gt;</span>springmvc<span class="hljs-tag">&lt;/<span class="hljs-name">servlet-name</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">servlet-class</span>&gt;</span>org.springframework.web.servlet.DispatcherServlet<span class="hljs-tag">&lt;/<span class="hljs-name">servlet-class</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">init-param</span>&gt;</span>
   <span class="hljs-tag">&lt;<span class="hljs-name">param-name</span>&gt;</span>contextConfigLocation<span class="hljs-tag">&lt;/<span class="hljs-name">param-name</span>&gt;</span>
   <span class="hljs-tag">&lt;<span class="hljs-name">param-value</span>&gt;</span>classpath:springmvc-config.xml<span class="hljs-tag">&lt;/<span class="hljs-name">param-value</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">init-param</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">load-on-startup</span>&gt;</span>1<span class="hljs-tag">&lt;/<span class="hljs-name">load-on-startup</span>&gt;</span>
 <span class="hljs-tag">&lt;/<span class="hljs-name">servlet</span>&gt;</span>
 <span class="hljs-tag">&lt;<span class="hljs-name">servlet-mapping</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">servlet-name</span>&gt;</span>springmvc<span class="hljs-tag">&lt;/<span class="hljs-name">servlet-name</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">url-pattern</span>&gt;</span>/<span class="hljs-tag">&lt;/<span class="hljs-name">url-pattern</span>&gt;</span>
 <span class="hljs-tag">&lt;/<span class="hljs-name">servlet-mapping</span>&gt;</span>
</code></pre>
<p><strong>springmvc&#x914D;&#x7F6E;&#x6587;&#x4EF6;</strong></p>
<pre><code class="lang-xml"><span class="php"><span class="hljs-meta">&lt;?</span>xml version=<span class="hljs-string">&quot;1.0&quot;</span> encoding=<span class="hljs-string">&quot;UTF-8&quot;</span><span class="hljs-meta">?&gt;</span></span>
<span class="hljs-tag">&lt;<span class="hljs-name">beans</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">&quot;http://www.springframework.org/schema/beans&quot;</span>
    <span class="hljs-attr">xmlns:xsi</span>=<span class="hljs-string">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span> 
    <span class="hljs-attr">xmlns:context</span>=<span class="hljs-string">&quot;http://www.springframework.org/schema/context&quot;</span>
    <span class="hljs-attr">xmlns:mvc</span>=<span class="hljs-string">&quot;http://www.springframework.org/schema/mvc&quot;</span>
    <span class="hljs-attr">xsi:schemaLocation</span>=<span class="hljs-string">&quot;http://www.springframework.org/schema/beans 
         http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc.xsd&quot;</span>&gt;</span>
    <span class="hljs-comment">&lt;!--&#x914D;&#x7F6E;&#x5904;&#x7406;&#x5668;&#x6620;&#x5C04;&#x5668;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;beanNameUrlHandlerMapping&quot;</span>          <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping&quot;</span>/&gt;</span>
    <span class="hljs-comment">&lt;!--&#x914D;&#x7F6E;&#x5904;&#x7406;&#x5668;&#x9002;&#x914D;&#x5668;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">bean</span>  <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;controllerHandlerAdapter&quot;</span>  <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter&quot;</span>/&gt;</span>

    <span class="hljs-comment">&lt;!--&#x914D;&#x7F6E;&#x89C6;&#x56FE;&#x89E3;&#x6790;&#x5668;--&gt;</span>
   <span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;org.springframework.web.servlet.view.InternalResourceViewResolver&quot;</span>&gt;</span>
       <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;prefix&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;/WEB-INF/page/&quot;</span>/&gt;</span>
       <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;suffix&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;.jsp&quot;</span>/&gt;</span>
   <span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span>

    <span class="hljs-comment">&lt;!--&#x914D;&#x7F6E;&#x5904;&#x7406;&#x5668;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;/hello&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;cn.kgc.springmvc.controller.HelloController&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span>
   -------------------------------------------------------------------------------------------- 
    <span class="hljs-comment">&lt;!--&#x6CE8;&#x89E3;&#x5B9E;&#x73B0;mvc--&gt;</span>
    <span class="hljs-comment">&lt;!-- &#x81EA;&#x52A8;&#x626B;&#x63CF;&#x5305;&#xFF0C;&#x5B9E;&#x73B0;&#x652F;&#x6301;&#x6CE8;&#x89E3;&#x7684;IOC --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">context:component-scan</span> <span class="hljs-attr">base-package</span>=<span class="hljs-string">&quot;cn.kgc.spring&quot;</span> /&gt;</span>
    <span class="hljs-comment">&lt;!-- &#x652F;&#x6301;mvc&#x6CE8;&#x89E3;&#x9A71;&#x52A8;  &#x6CE8;&#x518C;&#x5904;&#x7406;&#x5668;&#x6620;&#x5C04;&#x5668; &#x6CE8;&#x518C;&#x5904;&#x7406;&#x5668;&#x9002;&#x914D;&#x5668;  &#x53C2;&#x6570;&#x7684;&#x7C7B;&#x578B;&#x8F6C;&#x6362;  &#x9875;&#x9762;&#x8DF3;&#x8F6C;  &#x54CD;&#x5E94;&#x5904;&#x7406; --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">mvc:annotation-driven</span> /&gt;</span>
    <span class="hljs-comment">&lt;!-- &#x89C6;&#x56FE;&#x89E3;&#x6790;&#x5668; --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">bean</span>
        <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;org.springframework.web.servlet.view.InternalResourceViewResolver&quot;</span>
        <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;internalResourceViewResolver&quot;</span>&gt;</span>
        <span class="hljs-comment">&lt;!-- &#x524D;&#x7F00; --&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;prefix&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;/view/&quot;</span> /&gt;</span>
        <span class="hljs-comment">&lt;!-- &#x540E;&#x7F00; --&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;suffix&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;.jsp&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">beans</span>&gt;</span>
</code></pre>
<p>&#x521B;&#x5EFA; Controller&#xFF08;&#x5904;&#x7406;&#x8BF7;&#x6C42;&#x7684;&#x63A7;&#x5236;&#x5668;&#xFF09;</p>
<pre><code class="lang-java"><span class="hljs-meta">@Controller</span>
<span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/Hello&quot;</span>)
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">HelloWorld</span> </span>{
    <span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/Say.do&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">SayHi</span><span class="hljs-params">(Model model)</span> </span>{
        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;index&quot;</span>;
    }
}
</code></pre>
<p>&#x521B;&#x5EFA; View&#xFF08;&#x4F7F;&#x7528; JSP &#x4F5C;&#x4E3A;&#x89C6;&#x56FE;&#xFF09;</p>
<pre><code class="lang-jsp">&lt;%@ page contentType=&quot;text/html;charset=UTF-8&quot; language=&quot;java&quot; %&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;Title&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    hello springmvc
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
<p>&#x90E8;&#x7F72;&#x8FD0;&#x884C;</p>
<p><strong>@RequestMapping&#x8BE6;&#x89E3;</strong></p>
<p>1.&#x4E00;&#x4E2A;&#x65B9;&#x6CD5;&#x5339;&#x914D;&#x591A;&#x4E2A;&#x8DEF;&#x5F84;</p>
<pre><code class="lang-java"><span class="hljs-meta">@RequestMapping</span>(value={<span class="hljs-string">&quot;hello1.do&quot;</span>,<span class="hljs-string">&quot;hello2.do&quot;</span>})
    <span class="hljs-function"><span class="hljs-keyword">public</span>  String  <span class="hljs-title">test01</span><span class="hljs-params">()</span></span>{

        System.out.println(<span class="hljs-string">&quot;hello&quot;</span>);

        <span class="hljs-comment">//&#x8DF3;&#x8F6C;&#x8DEF;&#x5F84;  &#x9ED8;&#x8BA4;&#x4F7F;&#x7528;&#x8F6C;&#x53D1;  &#x4F1A;&#x7ECF;&#x8FC7;&#x89C6;&#x56FE;&#x89E3;&#x6790;&#x5668;</span>
        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;index&quot;</span>;
    }
</code></pre>
<p>2.&#x6307;&#x5B9A;&#x65B9;&#x6CD5;&#x63A5;&#x6536;&#x7684;&#x8BF7;&#x6C42;&#x65B9;&#x5F0F; </p>
<pre><code class="lang-java"><span class="hljs-meta">@RequestMapping</span>(value = <span class="hljs-string">&quot;hello1.do&quot;</span>,method = RequestMethod.GET)
    <span class="hljs-function"><span class="hljs-keyword">public</span>  String  <span class="hljs-title">test01</span><span class="hljs-params">()</span></span>{

        System.out.println(<span class="hljs-string">&quot;hello GET&quot;</span>);

        <span class="hljs-comment">//&#x8DF3;&#x8F6C;&#x8DEF;&#x5F84;  &#x9ED8;&#x8BA4;&#x4F7F;&#x7528;&#x8F6C;&#x53D1;  &#x4F1A;&#x7ECF;&#x8FC7;&#x89C6;&#x56FE;&#x89E3;&#x6790;&#x5668;</span>
        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;index&quot;</span>;
    }
</code></pre>
<p><img src="springmvc&#x6846;&#x67B6;.assets/image-20220704161641137.png" alt="image-20220704161641137"></p>
<p><img src="springmvc&#x6846;&#x67B6;.assets/image-20220704161800312.png" alt="image-20220704161800312"></p>
<pre><code class="lang-java"><span class="hljs-meta">@RequestMapping</span>(value = <span class="hljs-string">&quot;hello1.do&quot;</span>,method = RequestMethod.POST)
    <span class="hljs-function"><span class="hljs-keyword">public</span>  String  <span class="hljs-title">test02</span><span class="hljs-params">()</span></span>{

        System.out.println(<span class="hljs-string">&quot;hello POST&quot;</span>);

        <span class="hljs-comment">//&#x8DF3;&#x8F6C;&#x8DEF;&#x5F84;  &#x9ED8;&#x8BA4;&#x4F7F;&#x7528;&#x8F6C;&#x53D1;  &#x4F1A;&#x7ECF;&#x8FC7;&#x89C6;&#x56FE;&#x89E3;&#x6790;&#x5668;</span>
        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;index&quot;</span>;
    }
</code></pre>
<p><img src="springmvc&#x6846;&#x67B6;.assets/image-20220704161920866.png" alt="image-20220704161920866"></p>
<p><img src="springmvc&#x6846;&#x67B6;.assets/image-20220704162013869.png" alt="image-20220704162013869"></p>
<p>3.&#x4E00;&#x4E2A;&#x65B9;&#x6CD5;&#x6307;&#x5B9A;&#x591A;&#x79CD;&#x7C7B;&#x578B;&#x7684;&#x8BF7;&#x6C42;</p>
<pre><code class="lang-java"> <span class="hljs-meta">@RequestMapping</span>(value = <span class="hljs-string">&quot;hello1.do&quot;</span>,method = {RequestMethod.GET,RequestMethod.POST})
    <span class="hljs-function"><span class="hljs-keyword">public</span>  String  <span class="hljs-title">test01</span><span class="hljs-params">()</span></span>{

        System.out.println(<span class="hljs-string">&quot;hello GET OR POST&quot;</span>);

        <span class="hljs-comment">//&#x8DF3;&#x8F6C;&#x8DEF;&#x5F84;  &#x9ED8;&#x8BA4;&#x4F7F;&#x7528;&#x8F6C;&#x53D1;  &#x4F1A;&#x7ECF;&#x8FC7;&#x89C6;&#x56FE;&#x89E3;&#x6790;&#x5668;</span>
        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;index&quot;</span>;
    }
</code></pre>
<p><img src="springmvc&#x6846;&#x67B6;.assets/image-20220704162341476.png" alt="image-20220704162341476"></p>
<p><img src="springmvc&#x6846;&#x67B6;.assets/image-20220704162608835.png" alt="image-20220704162608835"></p>
<p><img src="springmvc&#x6846;&#x67B6;.assets/image-20220704162644823.png" alt="image-20220704162644823"></p>
<p><img src="springmvc&#x6846;&#x67B6;.assets/image-20220704162651203.png" alt="image-20220704162651203"></p>
<h2 id="springmvc&#x8DF3;&#x8F6C;&#x65B9;&#x5F0F;">SpringMVC&#x8DF3;&#x8F6C;&#x65B9;&#x5F0F;</h2>
<p>Spring MVC&#x9ED8;&#x8BA4;&#x91C7;&#x7528;&#x670D;&#x52A1;&#x5668;&#x5185;&#x90E8;&#x8F6C;&#x53D1;&#x7684;&#x5F62;&#x5F0F;&#x5C55;&#x793A;&#x9875;&#x9762;&#x4FE1;&#x606F;&#xFF0C;&#x540C;&#x65F6;&#x4E5F;&#x652F;&#x6301;&#x91CD;&#x5B9A;&#x5411;&#x9875;&#x9762;</p>
<p><strong>&#x91CD;&#x5B9A;&#x5411;</strong>&#xFF08;302&#x72B6;&#x6001;&#x7801;&#x7ED9;&#x6D4F;&#x89C8;&#x5668;&#xFF09;</p>
<pre><code class="lang-java"><span class="hljs-meta">@Controller</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">HelloController3</span> </span>{

    <span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/r1&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">test01</span><span class="hljs-params">(HttpServletRequest request,HttpServletResponse response)</span> <span class="hljs-keyword">throws</span> ServletException, IOException </span>{
        response.sendRedirect(<span class="hljs-string">&quot;redirect.jsp&quot;</span>);
    }

    <span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/r2&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">test02</span><span class="hljs-params">()</span></span>{
        <span class="hljs-keyword">return</span>  <span class="hljs-string">&quot;redirect:redirect.jsp&quot;</span>;
    }

    <span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/f1&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">test03</span><span class="hljs-params">(HttpServletRequest request,HttpServletResponse response)</span> <span class="hljs-keyword">throws</span>     ServletException, IOException </span>{
        request.getRequestDispatcher(<span class="hljs-string">&quot;redirect.jsp&quot;</span>).forward(request, response);
    }

    <span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/f2&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">test04</span><span class="hljs-params">()</span></span>{
        <span class="hljs-keyword">return</span>  <span class="hljs-string">&quot;forward:redirect.jsp&quot;</span>;
    }

    <span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/f3&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">test05</span><span class="hljs-params">()</span></span>{
        <span class="hljs-keyword">return</span>  <span class="hljs-string">&quot;redirect&quot;</span>;
    }
</code></pre>
<h2 id="springmvc&#x53C2;&#x6570;&#x7ED1;&#x5B9A;">SpringMVC&#x53C2;&#x6570;&#x7ED1;&#x5B9A;</h2>
<p><strong>&#x89C6;&#x56FE;&#x4F20;&#x53C2;&#x5230;&#x63A7;&#x5236;&#x5668;</strong></p>
<p><strong>1.&#x57FA;&#x672C;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x7ED1;&#x5B9A;</strong></p>
<p>&#x5F62;&#x53C2;&#x7684;&#x540D;&#x5B57;&#x548C;&#x4F20;&#x9012;&#x53C2;&#x6570;&#x7684;&#x540D;&#x5B57;&#x4FDD;&#x6301;&#x4E00;&#x81F4;&#xFF0C;&#x53C2;&#x6570;&#x9700;&#x8981;&#x5168;&#x90E8;&#x4F20;&#x9012;&#x5426;&#x5219;&#x62A5;500&#x9519;&#x8BEF;&#xFF0C;&#x4E3A;&#x4E86;&#x89E3;&#x51B3;&#x4E0D;&#x4F20;&#x53C2;&#x62A5;&#x9519;&#xFF0C;&#x53EF;&#x4EE5;&#x7ED9;&#x57FA;&#x672C;&#x7C7B;&#x578B;&#x7684;&#x53C2;&#x6570;&#x8BBE;&#x7F6E;&#x9ED8;&#x8BA4;&#x503C;</p>
<pre><code class="lang-java"> <span class="hljs-comment">/**
     * &#x8BBE;&#x7F6E;&#x57FA;&#x672C;&#x53C2;&#x6570;&#x7C7B;&#x578B;&#x7684;&#x9ED8;&#x8BA4;&#x503C; <span class="hljs-doctag">@RequestParam</span>(defaultValue = &quot;xx&quot;)
     *&#x5982;&#x679C;&#x901A;&#x8FC7;url&#x4F20;&#x9012;&#x4E86;&#x53C2;&#x6570;&#xFF0C;&#x5219;&#x4EE5;&#x4F20;&#x9012;&#x7684;&#x4E3A;&#x6700;&#x7EC8;&#x7684;&#x53C2;&#x6570;
     * <span class="hljs-doctag">@param</span> age
     * <span class="hljs-doctag">@param</span> score
     */</span>
    <span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/login2&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">login2</span><span class="hljs-params">(@RequestParam(defaultValue = <span class="hljs-string">&quot;20&quot;</span>)</span> <span class="hljs-keyword">int</span> age , @<span class="hljs-title">RequestParam</span><span class="hljs-params">(defaultValue = <span class="hljs-string">&quot;24.7&quot;</span>)</span> <span class="hljs-keyword">double</span> score)</span>{
        System.out.println(age);
        System.out.println(score);
    }
</code></pre>
<p><strong>&#x8BBE;&#x7F6E;&#x53C2;&#x6570;&#x7684;&#x522B;&#x540D;</strong></p>
<pre><code class="lang-java"> <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">login3</span><span class="hljs-params">(@RequestParam(defaultValue = <span class="hljs-string">&quot;20&quot;</span> ,name = <span class="hljs-string">&quot;Age&quot;</span>)</span> <span class="hljs-keyword">int</span> age , <span class="hljs-keyword">double</span> score)
 </span>{
        System.out.println(age);
        System.out.println(score);
 }
</code></pre>
<p><strong>2.&#x5305;&#x88C5;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x7684;&#x4F20;&#x9012;</strong></p>
<p>&#x4F7F;&#x7528;&#x5305;&#x88C5;&#x7C7B;&#x578B;&#x53EF;&#x4EE5;&#x89E3;&#x51B3;&#x57FA;&#x672C;&#x7C7B;&#x578B;&#x4E0D;&#x4F20;&#x9012;&#x503C;&#xFF0C;&#x51FA;&#x73B0;500&#x9519;&#x8BEF;&#x7684;&#x95EE;&#x9898;&#x4F46;&#x662F;&#x8FD8;&#x662F;&#x8981;&#x4FDD;&#x6301;&#x53C2;&#x6570;&#x540D;&#x5B57;&#x548C;&#x5F62;&#x53C2;&#x4FDD;&#x6301;&#x4E00;&#x81F4;&#xFF0C;</p>
<pre><code class="lang-java"> <span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/login4&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">login3</span><span class="hljs-params">(Integer age , Double score)</span></span>{
        System.out.println(age);
        System.out.println(score);
    }
</code></pre>
<p><strong>3.&#x5B57;&#x7B26;&#x4E32;&#x7C7B;&#x578B;&#x6570;&#x636E;&#x7684;&#x7ED1;&#x5B9A;</strong></p>
<p>&#x53C2;&#x7167;&#x5305;&#x88C5;&#x7C7B;&#x5373;&#x53EF;</p>
<p><strong>4.&#x6570;&#x7EC4;&#x7C7B;&#x578B;</strong></p>
<pre><code class="lang-java"> <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">login3</span><span class="hljs-params">(String[] ids)</span></span>{
        <span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i &lt; ids.length; i++) {
            System.out.println(ids[i]);
        }
  }
</code></pre>
<p><strong>5.javaBean&#x7C7B;&#x578B;</strong></p>
<p>&#x53C2;&#x6570;&#x540D;&#x7684;&#x5B57;&#x6BB5;&#x548C;Javabean&#x4E2D;&#x7684;&#x5C5E;&#x6027;&#x4FDD;&#x6301;&#x4E00;&#x81F4;&#x5373;&#x53EF;</p>
<pre><code class="lang-java"> <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">login3</span><span class="hljs-params">(User user)</span></span>{
        System.out.println(user);
    }
url:http:<span class="hljs-comment">//localhost:8080/user/login6?age=12&amp;username=lisi&amp;height=1.7</span>
</code></pre>
<p><strong>&#x8FD4;&#x56DE;&#x6570;&#x636E;&#x5230;&#x89C6;&#x56FE;&#x5C42;</strong></p>
<pre><code class="lang-java"><span class="hljs-meta">@RequestMapping</span>(path = <span class="hljs-string">&quot;/res1&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> ModelAndView <span class="hljs-title">test01</span><span class="hljs-params">()</span></span>{

        ModelAndView modelAndView = <span class="hljs-keyword">new</span> ModelAndView();
        modelAndView.setViewName(<span class="hljs-string">&quot;hello&quot;</span>);
        modelAndView.addObject(<span class="hljs-string">&quot;msg&quot;</span>, <span class="hljs-string">&quot;ModelAndView&quot;</span>);
        <span class="hljs-keyword">return</span> modelAndView;
    }

    <span class="hljs-meta">@RequestMapping</span>(path = <span class="hljs-string">&quot;/res2&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">test02</span><span class="hljs-params">(Model model)</span></span>{
        model.addAttribute(<span class="hljs-string">&quot;msg&quot;</span>, <span class="hljs-string">&quot;model&quot;</span>);
        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;hello&quot;</span>;
    }

    <span class="hljs-meta">@RequestMapping</span>(path = <span class="hljs-string">&quot;/res3&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">test03</span><span class="hljs-params">(ModelMap map)</span></span>{
        map.addAttribute(<span class="hljs-string">&quot;msg&quot;</span>, <span class="hljs-string">&quot;ModelMap&quot;</span>);
        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;hello&quot;</span>;
    }
</code></pre>
<h2 id="springmvc&#x5904;&#x7406;json&#x8BF7;&#x6C42;&#x548C;&#x54CD;&#x5E94;">SpringMVC&#x5904;&#x7406;json&#x8BF7;&#x6C42;&#x548C;&#x54CD;&#x5E94;</h2>
<p>&#x54CD;&#x5E94;json&#x683C;&#x5F0F;&#x7684;&#x6570;&#x636E;</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">JsonController</span> </span>{

    <span class="hljs-meta">@GetMapping</span>(<span class="hljs-string">&quot;/login/{username}/{password}&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">login</span><span class="hljs-params">(@PathVariable String username, @PathVariable String password, HttpServletResponse res)</span> <span class="hljs-keyword">throws</span> IOException </span>{
        System.out.println(username+<span class="hljs-string">&quot;::&quot;</span>+password);
        <span class="hljs-comment">//&#x54CD;&#x5E94;json&#x683C;&#x5F0F;&#x7684;&#x5B57;&#x7B26;&#x4E32;</span>
        res.setContentType(<span class="hljs-string">&quot;application/json;charset=utf-8&quot;</span>);
        JsonResult result = JsonResult.builder().code(<span class="hljs-number">200</span>).count(<span class="hljs-number">100L</span>).data(<span class="hljs-keyword">null</span>).msg(<span class="hljs-string">&quot;ok&quot;</span>).build();
        res.getWriter().write(result.toJSONString());
    }

    <span class="hljs-meta">@GetMapping</span>(<span class="hljs-string">&quot;/login2/{username}/{password}&quot;</span>)
    <span class="hljs-meta">@ResponseBody</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> Object <span class="hljs-title">login2</span><span class="hljs-params">(@PathVariable String username, @PathVariable String password, HttpServletResponse res)</span> <span class="hljs-keyword">throws</span> IOException </span>{
        System.out.println(username+<span class="hljs-string">&quot;::&quot;</span>+password);
        <span class="hljs-keyword">return</span> JsonResult.builder().code(<span class="hljs-number">200</span>).count(<span class="hljs-number">100L</span>).data(<span class="hljs-keyword">null</span>).msg(<span class="hljs-string">&quot;ok&quot;</span>).build();
    }

    <span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/login3&quot;</span>)
    <span class="hljs-meta">@ResponseBody</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> Object <span class="hljs-title">login3</span><span class="hljs-params">(User user)</span> </span>{
        System.out.println(user);
        <span class="hljs-keyword">return</span> user;
    }
</code></pre>
<p>&#x8BF7;&#x6C42;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x4E3A;JSON</p>
<pre><code class="lang-java"> /**
     * &#x63A5;&#x6536;json&#x683C;&#x5F0F;&#x7684;&#x53C2;&#x6570;
     * @param user
     * @return
     */
    @RequestMapping(&quot;/login4&quot;)
    @ResponseBody
    public Object login4(@RequestBody User user) {
        System.out.println(user);
        return user;
    }
}


&#x524D;&#x53F0;ajax&#x8BF7;&#x6C42;
&lt;script type=&quot;text/javascript&quot;&gt;
    $(function () {
        $(&quot;#jsbutton&quot;).click(function () {
            $.ajax({
                    url:&apos;/login3&apos;,
                    type:&apos;post&apos;,
                    data:{
                        username:&quot;lisi&quot;,
                        age:20,
                        height:170,
                        birth:new Date()
                    },
                    dataType:&apos;json&apos;,
                    success:function (result) {
                        console.log(result);
                    },
                    error:function () {
                         console.log(&quot;&#x8BF7;&#x6C42;&#x5931;&#x8D25;!&quot;)
                     }
            })
        })


        $(&quot;#jsbutton2&quot;).click(function () {
            var user = {
                username:&quot;lisi&quot;,
                age:20,
                height:170,
                birth:&apos;1999-9-9&apos;
            }
            $.ajax({
                url:&apos;/login4&apos;,
                type:&apos;post&apos;,
                data:JSON.stringify(user),
                contentType:&apos;application/json;charset=utf-8&apos;,
                dataType:&apos;json&apos;,
                success:function (result) {
                    console.log(result);
                },
                error:function () {
                    console.log(&quot;&#x8BF7;&#x6C42;&#x5931;&#x8D25;!&quot;)
                }
            })
        })

    })

&lt;/script&gt;
</code></pre>
<p><strong>RestFul&#x98CE;&#x683C;</strong></p>
<p>&#x4E00;&#x79CD;&#x8F6F;&#x4EF6;&#x67B6;&#x6784;&#x98CE;&#x683C;&#x3001;&#x8BBE;&#x8BA1;&#x98CE;&#x683C;&#xFF0C;&#x800C;<strong>&#x4E0D;&#x662F;</strong>&#x6807;&#x51C6;&#xFF0C;&#x53EA;&#x662F;&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x7EC4;&#x8BBE;&#x8BA1;&#x539F;&#x5219;&#x548C;&#x7EA6;&#x675F;&#x6761;&#x4EF6;&#x3002;&#x5B83;&#x4E3B;&#x8981;&#x7528;&#x4E8E;&#x5BA2;&#x6237;&#x7AEF;&#x548C;&#x670D;&#x52A1;&#x5668;&#x4EA4;&#x4E92;&#x7C7B;&#x7684;&#x8F6F;&#x4EF6;&#x3002;&#x57FA;&#x4E8E;&#x8FD9;&#x4E2A;&#x98CE;&#x683C;&#x8BBE;&#x8BA1;&#x7684;&#x8F6F;&#x4EF6;&#x53EF;&#x4EE5;&#x66F4;&#x7B80;&#x6D01;&#xFF0C;&#x66F4;&#x6709;&#x5C42;&#x6B21;&#xFF0C;&#x66F4;&#x6613;&#x4E8E;&#x5B9E;&#x73B0;&#x7F13;&#x5B58;&#x7B49;&#x673A;&#x5236;</p>
<p><strong>URL&#x5B9A;&#x4E49;</strong></p>
<p>&#x8D44;&#x6E90;&#xFF1A;&#x4E92;&#x8054;&#x7F51;&#x6240;&#x6709;&#x7684;&#x4E8B;&#x7269;&#x90FD;&#x53EF;&#x4EE5;&#x88AB;&#x62BD;&#x8C61;&#x4E3A;&#x8D44;&#x6E90; 
&#x8D44;&#x6E90;&#x64CD;&#x4F5C;&#xFF1A;&#x4F7F;&#x7528;POST&#x3001;DELETE&#x3001;PUT&#x3001;GET&#xFF0C;&#x4F7F;&#x7528;&#x4E0D;&#x540C;&#x65B9;&#x6CD5;&#x5BF9;&#x8D44;&#x6E90;&#x8FDB;&#x884C;&#x64CD;&#x4F5C;&#x3002; 
&#x5206;&#x522B;&#x5BF9;&#x5E94; &#x6DFB;&#x52A0;&#x3001; &#x5220;&#x9664;&#x3001;&#x4FEE;&#x6539;&#x3001;&#x67E5;&#x8BE2;</p>
<p><strong>&#x4F20;&#x7EDF;&#x65B9;&#x5F0F;&#x64CD;&#x4F5C;&#x8D44;&#x6E90;</strong> </p>
<pre><code class="lang-xml">http://127.0.0.1/item/queryUser.action?id=1       &#x67E5;&#x8BE2;,GET 
http://127.0.0.1/item/saveUser.action             &#x65B0;&#x589E;,POST 
http://127.0.0.1/item/updateUser.action           &#x66F4;&#x65B0;,POST 
http://127.0.0.1/item/deleteUser.action?id=1      &#x5220;&#x9664;,GET&#x6216;POST
</code></pre>
<p><strong>RestFul&#x8BF7;&#x6C42;&#x65B9;&#x5F0F;</strong>
&#x53EF;&#x4EE5;&#x901A;&#x8FC7; GET&#x3001; POST&#x3001; PUT&#x3001; PATCH&#x3001; DELETE &#x7B49;&#x65B9;&#x5F0F;&#x5BF9;&#x670D;&#x52A1;&#x7AEF;&#x7684;&#x8D44;&#x6E90;&#x8FDB;&#x884C;&#x64CD;&#x4F5C;&#x3002;&#x5176;&#x4E2D;:</p>
<ul>
<li>GET &#x7528;&#x4E8E;&#x67E5;&#x8BE2;&#x8D44;&#x6E90;&#xFF0C;</li>
<li>POST &#x7528;&#x4E8E;&#x521B;&#x5EFA;&#x8D44;&#x6E90;&#xFF0C;</li>
<li>PUT &#x7528;&#x4E8E;&#x66F4;&#x65B0;&#x670D;&#x52A1;&#x7AEF;&#x7684;&#x8D44;&#x6E90;&#x7684;&#x5168;&#x90E8;&#x4FE1;&#x606F;&#xFF0C;</li>
<li>DELETE &#x7528;&#x4E8E;&#x5220;&#x9664;&#x670D;&#x52A1;&#x7AEF;&#x7684;&#x8D44;&#x6E90;&#x3002;</li>
</ul>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">RestController</span> </span>{

    <span class="hljs-meta">@GetMapping</span>(<span class="hljs-string">&quot;/rest&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">test01</span><span class="hljs-params">()</span></span>{
        System.out.println(<span class="hljs-string">&quot;test01: &quot;</span>);
    }  

    <span class="hljs-meta">@PostMapping</span>(<span class="hljs-string">&quot;/rest&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">test02</span><span class="hljs-params">()</span></span>{
        System.out.println(<span class="hljs-string">&quot;test02: &quot;</span>);
    }

    <span class="hljs-meta">@DeleteMapping</span>(<span class="hljs-string">&quot;/rest&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">test03</span><span class="hljs-params">()</span></span>{
        System.out.println(<span class="hljs-string">&quot;test03:&quot;</span>);
    }

    <span class="hljs-meta">@PutMapping</span>(<span class="hljs-string">&quot;/rest&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">test04</span><span class="hljs-params">()</span></span>{
        System.out.println(<span class="hljs-string">&quot;test04: &quot;</span>);
    }

    <span class="hljs-meta">@PatchMapping</span>(<span class="hljs-string">&quot;/rest&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">test05</span><span class="hljs-params">()</span></span>{
        System.out.println(<span class="hljs-string">&quot;test05: &quot;</span>);
    }

}
</code></pre>
<p><strong>&#x8868;&#x5355;&#x53D1;&#x9001;PUT&#x8BF7;&#x6C42;&#x8BBE;&#x7F6E;&#x65B9;&#x5F0F;</strong></p>
<pre><code class="lang-html"> <span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">action</span>=<span class="hljs-string">&quot;rest/r&quot;</span> <span class="hljs-attr">method</span>=<span class="hljs-string">&quot;post&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;hidden&quot;</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;_method&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;PUT&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;text&quot;</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">&quot;&#x8BF7;&#x8F93;&#x5165;id&quot;</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;id&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;text&quot;</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">&quot;&#x8BF7;&#x8F93;&#x5165;&#x59D3;&#x540D;&quot;</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;username&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;date&quot;</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">&quot;&#x8BF7;&#x8F93;&#x5165;&#x751F;&#x65E5;&quot;</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;birth&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;submit&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
 <span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
</code></pre>
<p><strong>&#x8BBE;&#x7F6E;web.xml</strong></p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">filter</span>&gt;</span>
       <span class="hljs-tag">&lt;<span class="hljs-name">filter-name</span>&gt;</span>Hidden<span class="hljs-tag">&lt;/<span class="hljs-name">filter-name</span>&gt;</span>
       <span class="hljs-tag">&lt;<span class="hljs-name">filter-class</span>&gt;</span>org.springframework.web.filter.HiddenHttpMethodFilter<span class="hljs-tag">&lt;/<span class="hljs-name">filter-class</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">filter</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">filter-mapping</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">filter-name</span>&gt;</span>Hidden<span class="hljs-tag">&lt;/<span class="hljs-name">filter-name</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">url-pattern</span>&gt;</span>/*<span class="hljs-tag">&lt;/<span class="hljs-name">url-pattern</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">filter-mapping</span>&gt;</span>
</code></pre>
<p><strong>REST&#x98CE;&#x683C;&#x4F20;&#x53C2;&#x95EE;&#x9898;</strong></p>
<pre><code class="lang-java"> <span class="hljs-meta">@GetMapping</span>(<span class="hljs-string">&quot;/login/{username}/{password}&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">login</span><span class="hljs-params">(@PathVariable String username, @PathVariable String password, HttpServletResponse res)</span> <span class="hljs-keyword">throws</span> IOException </span>{
        System.out.println(username+<span class="hljs-string">&quot;::&quot;</span>+password);
        <span class="hljs-comment">//&#x54CD;&#x5E94;json&#x683C;&#x5F0F;&#x7684;&#x5B57;&#x7B26;&#x4E32;</span>
        res.setContentType(<span class="hljs-string">&quot;application/json;charset=utf-8&quot;</span>);
        JsonResult result = JsonResult.builder().code(<span class="hljs-number">200</span>).count(<span class="hljs-number">100L</span>).data(<span class="hljs-keyword">null</span>).msg(<span class="hljs-string">&quot;ok&quot;</span>).build();
        res.getWriter().write(result.toJSONString());
    }
</code></pre>
<p><strong>&#x6570;&#x636E;&#x63D0;&#x4EA4;&#x4E2D;&#x6587;&#x4E71;&#x7801;&#x7684;&#x5904;&#x7406;</strong></p>
<pre><code class="lang-xml"><span class="hljs-comment">&lt;!--&#x89E3;&#x51B3;&#x4E2D;&#x6587;&#x4E71;&#x7801;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">filter</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">filter-name</span>&gt;</span>encoding<span class="hljs-tag">&lt;/<span class="hljs-name">filter-name</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">filter-class</span>&gt;</span>org.springframework.web.filter.CharacterEncodingFilter<span class="hljs-tag">&lt;/<span class="hljs-name">filter-class</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">init-param</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">param-name</span>&gt;</span>encoding<span class="hljs-tag">&lt;/<span class="hljs-name">param-name</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">param-value</span>&gt;</span>utf-8<span class="hljs-tag">&lt;/<span class="hljs-name">param-value</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">init-param</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">filter</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">filter-mapping</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">filter-name</span>&gt;</span>encoding<span class="hljs-tag">&lt;/<span class="hljs-name">filter-name</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">url-pattern</span>&gt;</span>/*<span class="hljs-tag">&lt;/<span class="hljs-name">url-pattern</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">filter-mapping</span>&gt;</span>
</code></pre>
<h2 id="springmvc&#x9759;&#x6001;&#x8D44;&#x6E90;&#x5904;&#x7406;">SpringMVC&#x9759;&#x6001;&#x8D44;&#x6E90;&#x5904;&#x7406;</h2>
<p>1.&#x914D;&#x7F6E;&#x9759;&#x6001;&#x8D44;&#x6E90;&#x7684;&#x8DEF;&#x5F84;</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">mvc:resources</span> <span class="hljs-attr">mapping</span>=<span class="hljs-string">&quot;/static/**&quot;</span> <span class="hljs-attr">location</span>=<span class="hljs-string">&quot;/static/&quot;</span>/&gt;</span>
</code></pre>
<p>2.&#x914D;&#x7F6E;&#x4F7F;&#x7528;tomcat&#x7684;servlet&#x5904;&#x7406;&#x5668;</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">mvc:default-servlet-handler</span>/&gt;</span>
</code></pre>
<h2 id="springmvc&#x64CD;&#x4F5C;session&#x548C;cookie">SpringMVC&#x64CD;&#x4F5C;session&#x548C;cookie</h2>
<pre><code>@Controller
@SessionAttributes({&quot;model1&quot;,&quot;model2&quot;})
public class SessionController {

    @RequestMapping(&quot;/s1&quot;)
    public void test01(HttpSession session){
        session.setAttribute(&quot;msg&quot;, &quot;session attribute&quot;);
    }

    @RequestMapping(&quot;/s2&quot;)
    public void test02(HttpSession session){
        System.out.println(session.getAttribute(&quot;msg&quot;));
    }

    /**
     * &#x5C06;model&#x653E;&#x5165;session&#x4F5C;&#x7528;&#x57DF;
     * @param model
     */
    @RequestMapping(&quot;/s3&quot;)
    public void test03(Model model){
        model.addAttribute(&quot;model1&quot;, &quot;model1 attribute&quot;);
    }

    /**
     * &#x83B7;&#x53D6;&#x901A;&#x8FC7;&#x6CE8;&#x89E3;&#x8BBE;&#x7F6E;&#x7684;session&#x57DF;&#x4E2D;&#x7684;&#x503C;
     * @param session
     */
    @RequestMapping(&quot;/s5&quot;)
    public void test05(HttpSession session){
        System.out.println(&quot;msg: &quot;+session.getAttribute(&quot;msg&quot;));
        System.out.println(&quot;model1 :&quot;+session.getAttribute(&quot;model1&quot;));
        System.out.println(&quot;model2 :&quot;+session.getAttribute(&quot;model2&quot;));
    }

    /**
     * &#x901A;&#x8FC7;&#x6CE8;&#x89E3;&#x83B7;&#x53D6;session&#x57DF;&#x4E2D;&#x7684;&#x503C;
     * @param
     */
    @RequestMapping(&quot;/s6&quot;)
    public void test05(@SessionAttribute(name = &quot;msg&quot;) String session){
        System.out.println(session);
    }
</code></pre><p><strong>&#x64CD;&#x4F5C;cookie</strong></p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CookieController</span> </span>{

    <span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/c1&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">test01</span><span class="hljs-params">(HttpServletResponse response)</span></span>{
        Cookie ck = <span class="hljs-keyword">new</span> Cookie(<span class="hljs-string">&quot;cookie&quot;</span>,<span class="hljs-string">&quot;cookieValue&quot;</span>);
        ck.setPath(<span class="hljs-string">&quot;/&quot;</span>);
        ck.setMaxAge(<span class="hljs-number">60</span>*<span class="hljs-number">60</span>*<span class="hljs-number">24</span>*<span class="hljs-number">7</span>);
        response.addCookie(ck);
    }

    <span class="hljs-comment">/**
     * &#x83B7;&#x53D6;cookie&#x4E2D;&#x503C;&#x7684;&#x65B9;&#x5F0F;1
     * <span class="hljs-doctag">@param</span> request
     */</span>
    <span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/c2&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">test02</span><span class="hljs-params">(HttpServletRequest request)</span></span>{
        Cookie[] cookies = request.getCookies();
        <span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i &lt; cookies.length; i++) {
            System.out.println(cookies[i].getName()+<span class="hljs-string">&quot;:&quot;</span>+cookies[i].getValue());
        }
    }

    <span class="hljs-comment">/**
     * &#x83B7;&#x53D6;cookie&#x4E2D;&#x503C;&#x7684;&#x65B9;&#x5F0F;2  &#x6CE8;&#x89E3;&#x65B9;&#x5F0F;
     * <span class="hljs-doctag">@param</span> cookie
     */</span>
    <span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/c3&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">test03</span><span class="hljs-params">(@CookieValue(<span class="hljs-string">&quot;cookie&quot;</span>)</span> String cookie)</span>{
        System.out.println(cookie);
    }
}
</code></pre>
<h2 id="springmvc&#x62E6;&#x622A;&#x5668;">SpringMVC&#x62E6;&#x622A;&#x5668;</h2>
<p>SpringMVC&#x4E2D;&#x7684;Interceptor&#x62E6;&#x622A;&#x5668;&#x4E5F;&#x662F;&#x76F8;&#x5F53;&#x91CD;&#x8981;&#x548C;&#x76F8;&#x5F53;&#x6709;&#x7528;&#x7684;&#xFF0C;&#x5B83;&#x7684;&#x4E3B;&#x8981;&#x4F5C;&#x7528;&#x662F;&#x62E6;&#x622A;&#x7528;&#x6237;&#x7684;&#x8BF7;&#x6C42;&#x5E76;&#x8FDB;&#x884C;&#x76F8;&#x5E94;&#x7684;
&#x5904;&#x7406;&#x3002;&#x6BD4;&#x5982;&#x901A;&#x8FC7;&#x5B83;&#x6765;&#x8FDB;&#x884C;&#x6743;&#x9650;&#x9A8C;&#x8BC1;&#xFF0C;&#x6216;&#x8005;&#x662F;&#x6765;&#x5224;&#x65AD;&#x7528;&#x6237;&#x662F;&#x5426;&#x767B;&#x5F55;&#x7B49;&#x64CD;&#x4F5C;&#x3002;&#x5BF9;&#x4E8E;SpringMVC&#x62E6;&#x622A;&#x5668;&#x7684;&#x5B9A;&#x4E49;&#x65B9;&#x5F0F;&#x6709;&#x4E24;
&#x79CD;</p>
<ul>
<li>&#x5B9E;&#x73B0;&#x63A5;&#x53E3;: org.springframework.web.servlet.Handlerlnterceptor</li>
<li>&#x7EE7;&#x627F;&#x9002;&#x914D;&#x5668;: org.springframework.web.servethandler.HandlerInterceptorAdapter</li>
</ul>
<p><strong>1.&#x5B9E;&#x73B0;Handlerlnterceptor&#x63A5;&#x53E3;</strong></p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyIntercepter01</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">HandlerInterceptor</span> </span>{

    <span class="hljs-comment">/**
     * &#x76EE;&#x6807;&#x65B9;&#x6CD5;&#x6267;&#x884C;&#x524D;&#x6267;&#x884C;  &#x8FD4;&#x56DE;false&#x62E6;&#x622A;   &#x5426;&#x5219;&#x653E;&#x884C;
     * <span class="hljs-doctag">@param</span> request
     * <span class="hljs-doctag">@param</span> response
     * <span class="hljs-doctag">@param</span> handler
     * <span class="hljs-doctag">@return</span>
     * <span class="hljs-doctag">@throws</span> Exception
     */</span>
    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">boolean</span> <span class="hljs-title">preHandle</span><span class="hljs-params">(HttpServletRequest request, HttpServletResponse response, Object handler)</span> <span class="hljs-keyword">throws</span> Exception </span>{
        System.out.println(<span class="hljs-string">&quot;MyIntercepter01 -&gt;&#x76EE;&#x6807;&#x65B9;&#x6CD5;&#x524D;-&gt;&#x6267;&#x884C;preHandle01 &quot;</span>);
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">true</span>;
    }

    <span class="hljs-comment">/**
     *
     * &#x76EE;&#x6807;&#x65B9;&#x6CD5;&#x6267;&#x884C;&#x540E;&#x6267;&#x884C;
     * <span class="hljs-doctag">@param</span> request
     * <span class="hljs-doctag">@param</span> response
     * <span class="hljs-doctag">@param</span> handler
     * <span class="hljs-doctag">@param</span> modelAndView
     * <span class="hljs-doctag">@throws</span> Exception
     */</span>
    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">postHandle</span><span class="hljs-params">(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)</span> <span class="hljs-keyword">throws</span> Exception </span>{
        System.out.println(<span class="hljs-string">&quot;MyIntercepter01 -&gt;&#x76EE;&#x6807;&#x65B9;&#x6CD5;&#x6267;&#x884C;&#x540E;-&gt;&#x6267;&#x884C;postHandle01 &quot;</span>);
    }

    <span class="hljs-comment">/**
     * &#x89C6;&#x56FE;&#x54CD;&#x5E94;&#x5B8C;&#x6210;&#x540E;&#x6267;&#x884C;
     * <span class="hljs-doctag">@param</span> request
     * <span class="hljs-doctag">@param</span> response
     * <span class="hljs-doctag">@param</span> handler
     * <span class="hljs-doctag">@param</span> ex
     * <span class="hljs-doctag">@throws</span> Exception
     */</span>
    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">afterCompletion</span><span class="hljs-params">(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)</span> <span class="hljs-keyword">throws</span> Exception </span>{
        System.out.println(<span class="hljs-string">&quot;MyIntercepter01 -&gt;&#x89C6;&#x56FE;&#x6E32;&#x67D3;&#x5B8C;&#x6210;&#x540E;-&gt;&#x6267;&#x884C;afterCompletion01 &quot;</span>);
    }
</code></pre>
<p><strong>2.&#x7EE7;&#x627F;HandlerInterceptorAdapter</strong>&#xFF08;&#x4E0D;&#x5EFA;&#x8BAE;&#x4F7F;&#x7528;&#xFF09;</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyInterceptor2</span>  <span class="hljs-keyword">extends</span> <span class="hljs-title">HandlerInterceptorAdapter</span> </span>{
    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">boolean</span> <span class="hljs-title">preHandle</span><span class="hljs-params">(HttpServletRequest request, HttpServletResponse response, Object handler)</span> <span class="hljs-keyword">throws</span> Exception </span>{
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">false</span>;
    }
}
</code></pre>
<p><strong>&#x4F7F;&#x7528;&#x62E6;&#x622A;&#x5668;&#x62E6;&#x622A;&#x975E;&#x6CD5;&#x8BF7;&#x6C42;</strong></p>
<pre><code class="lang-java"><span class="hljs-comment">/**
 *&#x7528;&#x6237;&#x64CD;&#x4F5C;&#x6A21;&#x62DF;&#x5B9E;&#x73B0;
 * &#x7528;&#x6237;&#x7684;&#x767B;&#x5F55;(&#x65E0;&#x9700;&#x767B;&#x5F55;)
 * &#x7528;&#x6237;&#x7684;&#x6DFB;&#x52A0;(&#x767B;&#x5F55;)
 * &#x7528;&#x6237;&#x4FEE;&#x6539;(&#x767B;&#x5F55;)
 * &#x7528;&#x6237;&#x5220;&#x9664;(&#x767B;&#x5F55;)
 *
 * <span class="hljs-doctag">@author</span> mosin
 * date 2021/8/22
 * <span class="hljs-doctag">@version</span> 1.0
 */</span>
<span class="hljs-meta">@Controller</span>
<span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/user&quot;</span>)
<span class="hljs-meta">@SessionAttributes</span>(<span class="hljs-string">&quot;action&quot;</span>)
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">UserInfoController</span> </span>{
    <span class="hljs-comment">/**
     * &#x7528;&#x6237;&#x767B;&#x5F55;
     */</span>
    <span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/login&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> ModelAndView <span class="hljs-title">login</span><span class="hljs-params">(HttpSession session)</span></span>{
        ModelAndView modelAndView = <span class="hljs-keyword">new</span> ModelAndView();
        modelAndView.setViewName(<span class="hljs-string">&quot;success&quot;</span>);

        User user = User.builder().password(<span class="hljs-string">&quot;123456&quot;</span>).username(<span class="hljs-string">&quot;lisi&quot;</span>).build();
        session.setAttribute(<span class="hljs-string">&quot;user&quot;</span>, user);
        modelAndView.addObject(<span class="hljs-string">&quot;user&quot;</span>, user);
        <span class="hljs-keyword">return</span> modelAndView;
    }

    <span class="hljs-comment">/**
     * &#x7528;&#x6237;&#x6DFB;&#x52A0;
     */</span>
    <span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/add&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">add</span><span class="hljs-params">(Model model)</span></span>{
        model.addAttribute(<span class="hljs-string">&quot;action&quot;</span>, <span class="hljs-string">&quot;&#x7528;&#x6237;&#x6DFB;&#x52A0;&#x6210;&#x529F;&quot;</span>);
        System.out.println(<span class="hljs-string">&quot;&#x7528;&#x6237;&#x7684;&#x6DFB;&#x52A0;&#x65B9;&#x6CD5;&quot;</span>);

        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;success&quot;</span>;
    }

    <span class="hljs-comment">/**
     * &#x7528;&#x6237;&#x4FEE;&#x6539;
     */</span>
    <span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/update&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">update</span><span class="hljs-params">(Model model)</span></span>{
        System.out.println(<span class="hljs-string">&quot;&#x7528;&#x6237;&#x7684;&#x66F4;&#x65B0;&#x65B9;&#x6CD5;&quot;</span>);
        model.addAttribute(<span class="hljs-string">&quot;action&quot;</span>, <span class="hljs-string">&quot;&#x7528;&#x6237;&#x66F4;&#x65B0;&#x6210;&#x529F;&quot;</span>);
        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;success&quot;</span>;
    }

    <span class="hljs-comment">/**
     * &#x7528;&#x6237;&#x4FEE;&#x6539;
     */</span>
    <span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/delete&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">delete</span><span class="hljs-params">(Model model)</span></span>{
        System.out.println(<span class="hljs-string">&quot;&#x7528;&#x6237;&#x7684;&#x5220;&#x9664;&#x65B9;&#x6CD5;&quot;</span>);
        model.addAttribute(<span class="hljs-string">&quot;action&quot;</span>, <span class="hljs-string">&quot;&#x7528;&#x6237;&#x5220;&#x9664;&#x6210;&#x529F;&quot;</span>);
        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;success&quot;</span>;
    }

}
</code></pre>
<h2 id="springmvc&#x6587;&#x4EF6;&#x7684;&#x4E0A;&#x4F20;">SpringMVC&#x6587;&#x4EF6;&#x7684;&#x4E0A;&#x4F20;</h2>
<p>&#x6DFB;&#x52A0;&#x5750;&#x6807;&#x4F9D;&#x8D56;</p>
<pre><code class="lang-java">&lt;dependency&gt;
      &lt;groupId&gt;commons-fileupload&lt;/groupId&gt;
      &lt;artifactId&gt;commons-fileupload&lt;/artifactId&gt;
      &lt;version&gt;1.4&lt;/version&gt;
 &lt;/dependency&gt;
</code></pre>
<p>&#x914D;&#x7F6E;&#x89E3;&#x6790;&#x5668;</p>
<pre><code class="lang-java">&lt;!--    &#x6587;&#x4EF6;&#x4E0A;&#x4F20;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x89E3;&#x6790;&#x5668;--&gt;
    &lt;bean id=&quot;multipartResolver&quot; class=&quot;org.springframework.web.multipart.commons.CommonsMultipartResolver&quot;&gt;
&lt;!--       &#x5141;&#x8BB8;&#x4E0A;&#x4F20;&#x7684;&#x6700;&#x5927;&#x6587;&#x4EF6;  &#x5355;&#x4F4D;&#x5B57;&#x8282;--&gt;
        &lt;property name=&quot;maxUploadSize&quot; &gt;
            &lt;value&gt;104857600&lt;/value&gt;
        &lt;/property&gt;
&lt;!--        &#x5185;&#x5B58;&#x4E2D;&#x7684;&#x6700;&#x5927;&#x7F13;&#x5B58;&#x8D85;&#x51FA;&#x5199;&#x51FA;&#x4E34;&#x65F6;&#x6587;&#x4EF6;&#x5230;&#x786C;&#x76D8;--&gt;
        &lt;property name=&quot;maxInMemorySize&quot; &gt;
            &lt;value&gt;4096&lt;/value&gt;
        &lt;/property&gt;
        &lt;property name=&quot;defaultEncoding&quot;&gt;
            &lt;value&gt;utf-8&lt;/value&gt;
        &lt;/property&gt;
    &lt;/bean&gt;
</code></pre>
<p>&#x540E;&#x53F0;&#x4EE3;&#x7801;</p>
<pre><code class="lang-java"><span class="hljs-meta">@Controller</span>
<span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/upload&quot;</span>)
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">UPloadController</span> </span>{

    <span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/file&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">upload</span><span class="hljs-params">(@RequestParam(<span class="hljs-string">&quot;file&quot;</span>)</span> MultipartFile file, HttpServletRequest request)</span>{

        <span class="hljs-comment">//&#x83B7;&#x53D6;&#x9879;&#x76EE;&#x7684;&#x771F;&#x5B9E;&#x8DEF;&#x5F84;</span>
        String realPath = request.getSession().getServletContext().getRealPath(<span class="hljs-string">&quot;/&quot;</span>);
        System.out.println(realPath);
        <span class="hljs-comment">//&#x521B;&#x5EFA;&#x6587;&#x4EF6;&#x4E0A;&#x4F20;&#x7684;&#x76EE;&#x5F55;</span>
        File dir = <span class="hljs-keyword">new</span> File(realPath, <span class="hljs-string">&quot;/upload&quot;</span>);
        System.out.println(dir);
        <span class="hljs-comment">//&#x5224;&#x5B9A;&#x6587;&#x4EF6;&#x5939;&#x662F;&#x5426;&#x5B58;&#x5728; &#x4E0D;&#x5B58;&#x5728;&#x521B;&#x5EFA;</span>
        <span class="hljs-keyword">if</span>(!dir.exists()){
            dir.mkdir();
        }

        <span class="hljs-keyword">if</span>(!file.isEmpty()){
            <span class="hljs-comment">//&#x83B7;&#x53D6;&#x6587;&#x4EF6;&#x7684;&#x540D;&#x5B57;</span>
            String fileName = file.getOriginalFilename();
            <span class="hljs-comment">//&#x622A;&#x53D6;&#x6587;&#x4EF6;&#x7684;&#x540E;&#x7F00; &#x751F;&#x6210;&#x65B0;&#x7684;&#x6587;&#x4EF6;&#x540D; &#x907F;&#x514D;&#x6587;&#x4EF6;&#x540D;&#x5B57;&#x91CD;&#x590D;</span>
            String suffix= fileName.substring(fileName.lastIndexOf(<span class="hljs-string">&quot;.&quot;</span>));
            <span class="hljs-comment">//&#x83B7;&#x53D6;&#x5F53;&#x524D;&#x7CFB;&#x7EDF;&#x65F6;&#x95F4;</span>
            String fileLastName = System.currentTimeMillis()+suffix;
            System.out.println(fileLastName);
            <span class="hljs-comment">//&#x5C06;&#x6587;&#x4EF6;&#x5199;&#x5165;&#x76EE;&#x6807;&#x6587;&#x4EF6;&#x5939;</span>
            <span class="hljs-keyword">try</span> {
                file.transferTo(<span class="hljs-keyword">new</span> File(dir,fileLastName));
                request.setAttribute(<span class="hljs-string">&quot;msg&quot;</span>, <span class="hljs-string">&quot;&#x6587;&#x4EF6;&#x4E0A;&#x4F20;&#x6210;&#x529F;&quot;</span>);
            } <span class="hljs-keyword">catch</span> (IOException e) {
                e.printStackTrace();
                request.setAttribute(<span class="hljs-string">&quot;msg&quot;</span>, <span class="hljs-string">&quot;&#x6587;&#x4EF6;&#x4E0A;&#x4F20;&#x5931;&#x8D25;&quot;</span>);
            }
        }<span class="hljs-keyword">else</span>{
            request.setAttribute(<span class="hljs-string">&quot;msg&quot;</span>, <span class="hljs-string">&quot;&#x672A;&#x9009;&#x62E9;&#x6587;&#x4EF6;&quot;</span>);
        }

        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;success&quot;</span>;
    }

    <span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/files&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">uploads</span><span class="hljs-params">(@RequestParam(<span class="hljs-string">&quot;files&quot;</span>)</span> List&lt;MultipartFile&gt; files, HttpServletRequest request)</span>{

        <span class="hljs-comment">//&#x904D;&#x5386;&#x96C6;&#x5408;</span>
       files.forEach(multipartFile -&gt; {
           FileUploadUtil.upload(multipartFile, request);
       });
        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;success&quot;</span>;
    }
}
</code></pre>
<h2 id="springmvc&#x5168;&#x5C40;&#x5F02;&#x5E38;&#x7EDF;&#x4E00;&#x5904;&#x7406;">SpringMVC&#x5168;&#x5C40;&#x5F02;&#x5E38;&#x7EDF;&#x4E00;&#x5904;&#x7406;</h2>
<p>1.&#x5904;&#x7406;&#x7684;&#x65B9;&#x5F0F;1   &#x4F7F;&#x7528; @ExceptionHandler(Exception.class) &#x5728;&#x7C7B;&#x4E2D;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x5F02;&#x5E38;&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x5904;&#x7406;&#x672C;&#x7C7B;&#x4E2D;&#x7684;&#x6307;&#x5B9A;&#x5F02;&#x5E38;</p>
<pre><code class="lang-java"><span class="hljs-meta">@RestController</span>
<span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/exception&quot;</span>)
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ExceptionController01</span> </span>{

    <span class="hljs-meta">@ExceptionHandler</span>(Exception.class)
    <span class="hljs-function"><span class="hljs-keyword">public</span> Object <span class="hljs-title">handlerException</span><span class="hljs-params">(Exception e)</span></span>{
        <span class="hljs-keyword">return</span> JsonResult.builder().msg(<span class="hljs-string">&quot;&#x51FA;&#x73B0;&quot;</span>+<span class="hljs-string">&quot;&#x5F02;&#x5E38;&quot;</span>).code(<span class="hljs-number">1</span>).data(e.getMessage()).build();
    }

    <span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/e1&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> Object <span class="hljs-title">ex1</span><span class="hljs-params">()</span></span>{
        <span class="hljs-keyword">int</span> a  = <span class="hljs-number">1</span>/<span class="hljs-number">0</span>;
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">null</span>;
    }

    <span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/e2&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> Object <span class="hljs-title">ex2</span><span class="hljs-params">()</span> <span class="hljs-keyword">throws</span> FileNotFoundException </span>{
        <span class="hljs-keyword">new</span> FileInputStream(<span class="hljs-string">&quot;ab&quot;</span>);
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">null</span>;
    }
}
</code></pre>
<p>2.&#x5904;&#x7406;&#x7684;&#x65B9;&#x5F0F;2  &#x5168;&#x5C40;&#x5904;&#x7406;&#x6A21;&#x5F0F;  &#x5B9A;&#x4E49;ExceptionAdvice&#x7C7B;</p>
<pre><code class="lang-java"><span class="hljs-meta">@RestControllerAdvice</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ExceptionAdvice</span> </span>{

    <span class="hljs-meta">@ExceptionHandler</span>(value ={Exception.class})
    <span class="hljs-function"><span class="hljs-keyword">public</span> Object <span class="hljs-title">handlerException</span><span class="hljs-params">(Exception e)</span></span>{
        <span class="hljs-keyword">return</span> JsonResult.builder().msg(<span class="hljs-string">&quot;&#x51FA;&#x73B0;&quot;</span>+<span class="hljs-string">&quot;&#x5F02;&#x5E38;&quot;</span>).code(<span class="hljs-number">1</span>).data(e.getMessage()).build();
    }
}
</code></pre>
<h2 id="ssm&#x6846;&#x67B6;&#x6574;&#x5408;">SSM&#x6846;&#x67B6;&#x6574;&#x5408;</h2>
<h3 id="1&#x5F15;&#x5165;pom&#x4F9D;&#x8D56;">1.&#x5F15;&#x5165;pom&#x4F9D;&#x8D56;</h3>
<p>1.&#x5F15;&#x5165;mybatis&#x4F9D;&#x8D56;</p>
<pre><code class="lang-xml"><span class="hljs-comment">&lt;!--    mybatis&#x4F9D;&#x8D56;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.mybatis<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>mybatis<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>3.5.7<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
<span class="hljs-comment">&lt;!--    &#x5206;&#x9875;pagehelper--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>com.github.pagehelper<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>pagehelper<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>5.2.1<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
<span class="hljs-comment">&lt;!--    mybatis-spring--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.mybatis<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>mybatis-spring<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>2.0.5<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
</code></pre>
<p>2.&#x5F15;&#x5165;spring&#x4F9D;&#x8D56;</p>
<pre><code class="lang-xml"><span class="hljs-comment">&lt;!--    spring-context--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-context<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>5.3.9<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
<span class="hljs-comment">&lt;!--    spring-aspects--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-aspects<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>5.3.9<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
<span class="hljs-comment">&lt;!--      spring-jdbc--&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-jdbc<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>5.3.9<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
</code></pre>
<p>3.springmvc&#x4F9D;&#x8D56;</p>
<pre><code class="lang-xml"><span class="hljs-comment">&lt;!--    spring-webmvc--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-webmvc<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>5.3.9<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
<span class="hljs-comment">&lt;!--    jackson-core--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>com.fasterxml.jackson.core<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>jackson-core<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>2.11.3<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
<span class="hljs-comment">&lt;!--    jackson-databind--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>com.fasterxml.jackson.core<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>jackson-databind<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>2.11.3<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
<span class="hljs-comment">&lt;!--    jackson-annotations--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>com.fasterxml.jackson.core<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>jackson-annotations<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>2.11.3<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

<span class="hljs-comment">&lt;!--    &#x6587;&#x4EF6;&#x4E0A;&#x4F20;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>commons-fileupload<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>commons-fileupload<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>1.4<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
</code></pre>
<p>4.log4j&#x4F9D;&#x8D56;</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>log4j<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>log4j<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>1.2.17<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
 <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
       <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.apache.logging.log4j<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
       <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>log4j-api<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
       <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>2.13.3<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
 <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
       <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.apache.logging.log4j<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
       <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>log4j-core<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
       <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>2.13.1<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
</code></pre>
<p>5.&#x6570;&#x636E;&#x5E93;&#x9A71;&#x52A8;&#x548C;&#x8FDE;&#x63A5;&#x6C60;</p>
<pre><code class="lang-xml"><span class="hljs-comment">&lt;!--    mysql-connector--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>mysql<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>mysql-connector-java<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>5.1.44<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

<span class="hljs-comment">&lt;!--    druid&#x8FDE;&#x63A5;&#x6C60;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>com.alibaba<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>druid<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>1.1.10<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
</code></pre>
<p>6.servlet+jsp&#x4F9D;&#x8D56;</p>
<pre><code class="lang-xml"><span class="hljs-comment">&lt;!--servlet--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>javax.servlet<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>javax.servlet-api<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>4.0.1<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
<span class="hljs-comment">&lt;!--    jsp--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>javax.servlet.jsp<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>jsp-api<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>2.2<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
</code></pre>
<p>7.jstl&#x4F9D;&#x8D56;</p>
<pre><code class="lang-xml"><span class="hljs-comment">&lt;!--jstl--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>javax.servlet<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>jstl<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>1.2<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>taglibs<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>standard<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>1.1.2<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
</code></pre>
<p>8.&#x5176;&#x5B83;&#x4F9D;&#x8D56;</p>
<pre><code class="lang-xml"><span class="hljs-comment">&lt;!--    lombok--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.projectlombok<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>lombok<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>1.18.16<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
<span class="hljs-comment">&lt;!--    junit--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>junit<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>junit<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>4.11<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">scope</span>&gt;</span>test<span class="hljs-tag">&lt;/<span class="hljs-name">scope</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
</code></pre>
<h3 id="2&#x8BBE;&#x7F6E;&#x914D;&#x7F6E;&#x6587;&#x4EF6;">2.&#x8BBE;&#x7F6E;&#x914D;&#x7F6E;&#x6587;&#x4EF6;</h3>
<p>1.db.properties</p>
<pre><code class="lang-properties">jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql:///mybatis?useSSL=true&amp;serverTimezone=GMT%2B8
jdbc.username=root
jdbc.password=root

#&#x521D;&#x59CB;&#x5316;&#x65F6;&#x6C60;&#x4E2D;&#x5EFA;&#x7ACB;&#x7684;&#x8FDE;&#x63A5;&#x6570;&#x3002;
jdbc.initialSize=2
#&#x6700;&#x5927;&#x7684;&#x53EF;&#x6D3B;&#x8DC3;&#x7684;&#x8FDE;&#x63A5;&#x6C60;&#x6570;&#x91CF;
jdbc.maxActive=300
#&#x6700;&#x5927;&#x7B49;&#x5F85;&#x65F6;&#x95F4;
jdbc.maxWait=60000
</code></pre>
<p>2.log4j.properties</p>
<pre><code class="lang-properties">log4j.rootLogger=DEBUG,Console

#Console
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.console.Target=System.out
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n

log4j.logger.org.apache=ERROR
log4j.logger.org.mybatis=ERROR
log4j.logger.org.springframework=ERROR

#&#x8FD9;&#x4E2A;&#x9700;&#x8981;
log4j.logger.log4jdbc.debug=ERROR
log4j.logger.com.gk.mapper=ERROR
log4j.logger.jdbc.audit=ERROR
log4j.logger.jdbc.resultset=ERROR
#&#x8FD9;&#x4E2A;&#x6253;&#x5370;SQL&#x8BED;&#x53E5;&#x975E;&#x5E38;&#x91CD;&#x8981;
log4j.logger.jdbc.sqlonly=DEBUG
log4j.logger.jdbc.sqltiming=ERROR
log4j.logger.jdbc.connection=FATAL
</code></pre>
<p>3.spring&#x6838;&#x5FC3;&#x914D;&#x7F6E;&#x6587;&#x4EF6;</p>
<pre><code class="lang-xml"><span class="php"><span class="hljs-meta">&lt;?</span>xml version=<span class="hljs-string">&quot;1.0&quot;</span> encoding=<span class="hljs-string">&quot;UTF-8&quot;</span><span class="hljs-meta">?&gt;</span></span>
<span class="hljs-tag">&lt;<span class="hljs-name">beans</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">&quot;http://www.springframework.org/schema/beans&quot;</span>
       <span class="hljs-attr">xmlns:xsi</span>=<span class="hljs-string">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span>
       <span class="hljs-attr">xmlns:context</span>=<span class="hljs-string">&quot;http://www.springframework.org/schema/context&quot;</span>
       <span class="hljs-attr">xmlns:mvc</span>=<span class="hljs-string">&quot;http://www.springframework.org/schema/mvc&quot;</span>
       <span class="hljs-attr">xmlns:tx</span>=<span class="hljs-string">&quot;http://www.springframework.org/schema/tx&quot;</span>
       <span class="hljs-attr">xsi:schemaLocation</span>=<span class="hljs-string">&quot;http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd&quot;</span>&gt;</span>
    <span class="hljs-comment">&lt;!-- &#x8BFB;&#x53D6;db.properties --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">context:property-placeholder</span> <span class="hljs-attr">location</span>=<span class="hljs-string">&quot;classpath:db.properties&quot;</span> /&gt;</span>

    <span class="hljs-comment">&lt;!-- &#x914D;&#x7F6E;&#x6570;&#x636E;&#x6E90; --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;dataSource&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;com.alibaba.druid.pool.DruidDataSource&quot;</span>&gt;</span>
        <span class="hljs-comment">&lt;!-- &#x6570;&#x636E;&#x5E93;&#x9A71;&#x52A8; --&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;driverClassName&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;${jdbc.driver}&quot;</span> /&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;url&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;${jdbc.url}&quot;</span> /&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;username&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;${jdbc.username}&quot;</span> /&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;password&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;${jdbc.password}&quot;</span> /&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;initialSize&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;${jdbc.initialSize}&quot;</span> /&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;maxActive&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;${jdbc.maxActive}&quot;</span> /&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;maxWait&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;${jdbc.maxWait}&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span>

    <span class="hljs-comment">&lt;!-- &#x4E8B;&#x52A1;&#x7BA1;&#x7406;&#x5668;&#xFF0C;&#x4F9D;&#x8D56;&#x4E8E;&#x6570;&#x636E;&#x6E90; --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;transactionManager&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;org.springframework.jdbc.datasource.DataSourceTransactionManager&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;dataSource&quot;</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;dataSource&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span>

    <span class="hljs-comment">&lt;!-- &#x5F00;&#x542F;&#x4E8B;&#x52A1;&#x6CE8;&#x89E3; --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">tx:annotation-driven</span> <span class="hljs-attr">transaction-manager</span>=<span class="hljs-string">&quot;transactionManager&quot;</span>  /&gt;</span>

    <span class="hljs-comment">&lt;!-- &#x914D;&#x7F6E;MyBatis&#x5DE5;&#x5382; SqlSessionFactory --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;sqlSessionFactory&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;org.mybatis.spring.SqlSessionFactoryBean&quot;</span>&gt;</span>
        <span class="hljs-comment">&lt;!-- &#x6CE8;&#x5165;&#x6570;&#x636E;&#x6E90; --&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;dataSource&quot;</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;dataSource&quot;</span> /&gt;</span>
        <span class="hljs-comment">&lt;!-- &#x6307;&#x5B9A;Mybatis&#x6838;&#x5FC3;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x4F4D;&#x7F6E; --&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;configLocation&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;classpath:config/mybatis-config.xml&quot;</span> /&gt;</span>
        <span class="hljs-comment">&lt;!-- &#x626B;&#x63CF;&#x6A21;&#x5757;&#x914D;&#x7F6E;&#x6587;&#x4EF6;:mapper&#x9700;&#x8981;&#x7684;xml&#x6587;&#x4EF6;&#xFF08;&#x5982;&#x679C;mapper.xml&#x548C;&#x63A5;&#x53E3;&#x5728;&#x4E00;&#x4E2A;&#x5305;&#x4E0B;&#xFF0C;&#x53EF;&#x4EE5;&#x4E0D;&#x914D;&#x7F6E;&#xFF09; --&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;mapperLocations&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;classpath:mapper/*.xml&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span>

    <span class="hljs-comment">&lt;!-- &#x914D;&#x7F6E;mapper&#x626B;&#x63CF;&#x5668; --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;org.mybatis.spring.mapper.MapperScannerConfigurer&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;basePackage&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;cn.kgc.ssm.dao&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span>

    <span class="hljs-comment">&lt;!-- &#x626B;&#x63CF;&#x5305;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">context:component-scan</span> <span class="hljs-attr">base-package</span>=<span class="hljs-string">&quot;cn.kgc.ssm&quot;</span> /&gt;</span>
    <span class="hljs-comment">&lt;!--    &#x5F00;&#x542F;spring&#x6CE8;&#x89E3;&#x652F;&#x6301;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">context:annotation-config</span>/&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">beans</span>&gt;</span>
</code></pre>
<p>4.spring-mvc&#x914D;&#x7F6E;&#x6587;&#x4EF6;</p>
<pre><code class="lang-xml"><span class="php"><span class="hljs-meta">&lt;?</span>xml version=<span class="hljs-string">&quot;1.0&quot;</span> encoding=<span class="hljs-string">&quot;UTF-8&quot;</span><span class="hljs-meta">?&gt;</span></span>
<span class="hljs-tag">&lt;<span class="hljs-name">beans</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">&quot;http://www.springframework.org/schema/beans&quot;</span>
       <span class="hljs-attr">xmlns:xsi</span>=<span class="hljs-string">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span>
       <span class="hljs-attr">xmlns:context</span>=<span class="hljs-string">&quot;http://www.springframework.org/schema/context&quot;</span>
       <span class="hljs-attr">xmlns:mvc</span>=<span class="hljs-string">&quot;http://www.springframework.org/schema/mvc&quot;</span>
       <span class="hljs-attr">xmlns:tx</span>=<span class="hljs-string">&quot;http://www.springframework.org/schema/tx&quot;</span>
       <span class="hljs-attr">xsi:schemaLocation</span>=<span class="hljs-string">&quot;http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd&quot;</span>&gt;</span>

    <span class="hljs-comment">&lt;!-- &#x52A0;&#x8F7D;&#x6CE8;&#x89E3;&#x9A71;&#x52A8; --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">mvc:annotation-driven</span> /&gt;</span>
    <span class="hljs-comment">&lt;!-- &#x914D;&#x7F6E;&#x89C6;&#x56FE;&#x89E3;&#x6790;&#x5668; --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;org.springframework.web.servlet.view.InternalResourceViewResolver&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;prefix&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;/WEB-INF/pages/&quot;</span> /&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;suffix&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;.jsp&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span>
    <span class="hljs-comment">&lt;!--&#x91CA;&#x653E;&#x9759;&#x6001;&#x8D44;&#x6E90;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">mvc:default-servlet-handler</span>/&gt;</span>
    <span class="hljs-comment">&lt;!--    &#x6587;&#x4EF6;&#x4E0A;&#x4F20;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x89E3;&#x6790;&#x5668;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;multipartResolver&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;org.springframework.web.multipart.commons.CommonsMultipartResolver&quot;</span>&gt;</span>
        <span class="hljs-comment">&lt;!--       &#x5141;&#x8BB8;&#x4E0A;&#x4F20;&#x7684;&#x6700;&#x5927;&#x6587;&#x4EF6;--&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;maxUploadSize&quot;</span> &gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>104857600<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span>
        <span class="hljs-comment">&lt;!--        &#x5185;&#x5B58;&#x4E2D;&#x7684;&#x6700;&#x5927;&#x7F13;&#x5B58;&#x8D85;&#x51FA;&#x5199;&#x51FA;&#x4E34;&#x65F6;&#x6587;&#x4EF6;&#x5230;&#x786C;&#x76D8;--&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;maxInMemorySize&quot;</span> &gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>4096<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;defaultEncoding&quot;</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>utf-8<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">beans</span>&gt;</span>
</code></pre>
<p>5.mybatis&#x914D;&#x7F6E;&#x6587;&#x4EF6;</p>
<pre><code class="lang-xml"><span class="php"><span class="hljs-meta">&lt;?</span>xml version=<span class="hljs-string">&quot;1.0&quot;</span> encoding=<span class="hljs-string">&quot;UTF-8&quot;</span> <span class="hljs-meta">?&gt;</span></span>
<span class="hljs-meta">&lt;!DOCTYPE configuration
        PUBLIC &quot;-//mybatis.org//DTD Config 3.0//EN&quot;
        &quot;http://mybatis.org/dtd/mybatis-3-config.dtd&quot;&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>
    <span class="hljs-comment">&lt;!-- mybatis&#x8FD0;&#x884C;&#x65F6;&#x8BBE;&#x7F6E; --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">settings</span>&gt;</span>
        <span class="hljs-comment">&lt;!-- &#x542F;&#x7528;log4j&#x65E5;&#x5FD7; --&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">setting</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;logImpl&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;LOG4J&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">setting</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">setting</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;mapUnderscoreToCamelCase&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;true&quot;</span>/&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">settings</span>&gt;</span>
    <span class="hljs-comment">&lt;!-- &#x522B;&#x540D;&#x5B9A;&#x4E49; --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">typeAliases</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">package</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;cn.kgc.ssm.entity&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">typeAliases</span>&gt;</span>

    <span class="hljs-comment">&lt;!-- mybatis&#x63D2;&#x4EF6; --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">plugins</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">plugin</span> <span class="hljs-attr">interceptor</span>=<span class="hljs-string">&quot;com.github.pagehelper.PageInterceptor&quot;</span>&gt;</span>
            <span class="hljs-comment">&lt;!-- &#x914D;&#x7F6E;mysql&#x65B9;&#x8A00; --&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;helperDialect&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;mysql&quot;</span> /&gt;</span>
            <span class="hljs-comment">&lt;!-- &#x8BBE;&#x7F6E;&#x4E3A;true&#x65F6;&#xFF0C;&#x5982;&#x679C;pageSize=0&#x5C31;&#x4F1A;&#x67E5;&#x8BE2;&#x51FA;&#x5168;&#x90E8;&#x7684;&#x7ED3;&#x679C; --&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;pageSizeZero&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;true&quot;</span> /&gt;</span>
            <span class="hljs-comment">&lt;!-- 3.3.0&#x7248;&#x672C;&#x53EF;&#x7528;&#xFF0C;&#x5206;&#x9875;&#x53C2;&#x6570;&#x5408;&#x7406;&#x5316;&#xFF0C;&#x9ED8;&#x8BA4;false&#x7981;&#x7528; --&gt;</span>
            <span class="hljs-comment">&lt;!-- &#x542F;&#x7528;&#x5408;&#x7406;&#x5316;&#x65F6;&#xFF0C;&#x5982;&#x679C;pageNum&lt;1&#x4F1A;&#x67E5;&#x8BE2;&#x7B2C;&#x4E00;&#x9875;&#xFF0C;&#x5982;&#x679C;pageNum&gt;pages&#x4F1A;&#x67E5;&#x8BE2;&#x6700;&#x540E;&#x4E00;&#x9875; --&gt;</span>
            <span class="hljs-comment">&lt;!-- &#x7981;&#x7528;&#x5408;&#x7406;&#x5316;&#x65F6;&#xFF0C;&#x5982;&#x679C;pageNum&lt;1&#x6216;pageNum&gt;pages&#x4F1A;&#x8FD4;&#x56DE;&#x7A7A;&#x6570;&#x636E; --&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;reasonable&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;true&quot;</span> /&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">plugin</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">plugins</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<p>6.web.xml</p>
<pre><code class="lang-xml"><span class="php"><span class="hljs-meta">&lt;?</span>xml version=<span class="hljs-string">&quot;1.0&quot;</span> encoding=<span class="hljs-string">&quot;UTF-8&quot;</span><span class="hljs-meta">?&gt;</span></span>
<span class="hljs-tag">&lt;<span class="hljs-name">web-app</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">&quot;http://xmlns.jcp.org/xml/ns/javaee&quot;</span>
         <span class="hljs-attr">xmlns:xsi</span>=<span class="hljs-string">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span>
         <span class="hljs-attr">xsi:schemaLocation</span>=<span class="hljs-string">&quot;http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd&quot;</span>
         <span class="hljs-attr">version</span>=<span class="hljs-string">&quot;4.0&quot;</span>&gt;</span>
<span class="hljs-comment">&lt;!--    &#x524D;&#x7AEF;&#x63A7;&#x5236;&#x5668;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">servlet</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">servlet-name</span>&gt;</span>ssm<span class="hljs-tag">&lt;/<span class="hljs-name">servlet-name</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">servlet-class</span>&gt;</span>org.springframework.web.servlet.DispatcherServlet<span class="hljs-tag">&lt;/<span class="hljs-name">servlet-class</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">init-param</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">param-name</span>&gt;</span>contextConfigLocation<span class="hljs-tag">&lt;/<span class="hljs-name">param-name</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">param-value</span>&gt;</span>classpath:config/spring-*.xml<span class="hljs-tag">&lt;/<span class="hljs-name">param-value</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">init-param</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">load-on-startup</span>&gt;</span>1<span class="hljs-tag">&lt;/<span class="hljs-name">load-on-startup</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">servlet</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">servlet-mapping</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">servlet-name</span>&gt;</span>ssm<span class="hljs-tag">&lt;/<span class="hljs-name">servlet-name</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">url-pattern</span>&gt;</span>*.do<span class="hljs-tag">&lt;/<span class="hljs-name">url-pattern</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">servlet-mapping</span>&gt;</span>

<span class="hljs-comment">&lt;!--    &#x8FC7;&#x6EE4;&#x5668;&#x89E3;&#x51B3;&#x4E2D;&#x6587;&#x4E71;&#x7801;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">filter</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">filter-name</span>&gt;</span>encoding<span class="hljs-tag">&lt;/<span class="hljs-name">filter-name</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">filter-class</span>&gt;</span>org.springframework.web.filter.CharacterEncodingFilter<span class="hljs-tag">&lt;/<span class="hljs-name">filter-class</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">init-param</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">param-name</span>&gt;</span>encoding<span class="hljs-tag">&lt;/<span class="hljs-name">param-name</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">param-value</span>&gt;</span>utf-8<span class="hljs-tag">&lt;/<span class="hljs-name">param-value</span>&gt;</span>
         <span class="hljs-tag">&lt;/<span class="hljs-name">init-param</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">filter</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">filter-mapping</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">filter-name</span>&gt;</span>encoding<span class="hljs-tag">&lt;/<span class="hljs-name">filter-name</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">url-pattern</span>&gt;</span>/<span class="hljs-tag">&lt;/<span class="hljs-name">url-pattern</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">filter-mapping</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">web-app</span>&gt;</span>
</code></pre>
<h3 id="3&#x9879;&#x76EE;&#x76EE;&#x5F55;&#x7ED3;&#x6784;">3.&#x9879;&#x76EE;&#x76EE;&#x5F55;&#x7ED3;&#x6784;</h3>
<p><img src="springmvc&#x6846;&#x67B6;.assets/image-20210824234733309.png" alt="image-20210824234733309"></p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="SpringBoot.html" class="navigation navigation-prev " aria-label="Previous page: SpringBoot">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="spring框架.html" class="navigation navigation-next " aria-label="Next page: Spring框架">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Springmvc框架","level":"2.6.3","depth":2,"next":{"title":"Spring框架","level":"2.6.4","depth":2,"path":"books/整合/spring框架.md","ref":"books/整合/spring框架.md","articles":[]},"previous":{"title":"SpringBoot","level":"2.6.2","depth":2,"path":"books/整合/SpringBoot.md","ref":"books/整合/SpringBoot.md","articles":[]},"dir":"ltr"},"config":{"plugins":["search-pro","code","back-to-top-button","theme-comscore","intopic-toc","flexible-alerts","expandable-chapters"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"intopic-toc":{"selector":".markdown-section h1, .markdown-section h2, .markdown-section h3, .markdown-section h4, .markdown-section h5, .markdown-section h6","mode":"nested","maxDepth":6,"isCollapsed":true,"isScrollspyActive":true,"visible":true,"label":"In this article"},"search-pro":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"code":{"copyButtons":true},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"theme-comscore":{},"back-to-top-button":{},"flexible-alerts":{"style":"callout","note":{"label":"Note","icon":"fa fa-info-circle","className":"info"},"tip":{"label":"Tip","icon":"fa fa-lightbulb-o","className":"tip"},"warning":{"label":"Warning","icon":"fa fa-exclamation-triangle","className":"warning"},"danger":{"label":"Attention","icon":"fa fa-ban","className":"danger"}},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{}},"theme":"default","author":"作者","lang":"zh-cn","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"isbn":"图书编号","variables":{},"title":"书名","gitbook":"*","description":"描述"},"file":{"path":"books/整合/springmvc框架.md","mtime":"2022-07-06T12:08:08.073Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2023-03-01T12:24:55.135Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-intopic-toc/anchor.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-intopic-toc/gumshoe.polyfills.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-intopic-toc/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-flexible-alerts/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

